master
zhuce 2023-12-29 17:37:14 +08:00
parent 85f34f27d7
commit aad65b63c6
10 changed files with 109 additions and 6 deletions

View File

@ -2,6 +2,7 @@
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:autosos_maui"
xmlns:converter="clr-namespace:autosos_maui.Converters"
x:Class="autosos_maui.App">
<Application.Resources>
<ResourceDictionary>
@ -9,6 +10,7 @@
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<converter:BoolNegationConverter x:Key="BoolNegationConverter"/>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -1,4 +1,6 @@
namespace autosos_maui;
using autosos_maui.Views;
namespace autosos_maui;
public partial class App : Application
{
@ -7,5 +9,7 @@ public partial class App : Application
InitializeComponent();
MainPage = new AppShell();
Routing.RegisterRoute("HomeView",typeof(HomeView));
}
}
}

View File

@ -0,0 +1,21 @@
using System.Globalization;
namespace autosos_maui.Converters;
public class BoolNegationConverter: IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue; // 返回布尔值的相反值
}
return value; // 返回原始值(或者你可以返回默认的可见性)
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@ -32,6 +32,7 @@ public static class MauiProgram
public static MauiAppBuilder RegisterViews(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddTransient<LoginView>();
mauiAppBuilder.Services.AddTransient<HomeView>();
return mauiAppBuilder;
}
@ -39,7 +40,7 @@ public static class MauiProgram
public static MauiAppBuilder RegisterViewModels(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddSingleton<LoginViewModel>();
mauiAppBuilder.Services.AddSingleton<HomeViewModel>();
return mauiAppBuilder;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -0,0 +1,15 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace autosos_maui.ViewModels;
public partial class HomeViewModel: ObservableObject
{
private bool _isToggled = false;
public bool IsToggled
{
get => _isToggled;
set => SetProperty(ref _isToggled, value);
}
}

View File

@ -6,13 +6,26 @@ namespace autosos_maui.ViewModels;
public partial class LoginViewModel : ObservableObject
{
[ObservableProperty] private string _userName = "";
[ObservableProperty] private string _password = "";
private string _userName = "";
private string _password = "";
public string UserName
{
get => _userName;
set => SetProperty(ref _userName, value);
}
public string Password
{
get => _password;
set => SetProperty(ref _password, value);
}
[RelayCommand]
public void Login()
{
Debug.WriteLine("login");
Debug.WriteLine("username:{0},password:{1}",_userName,_password);
Debug.WriteLine("username:{0},password:{1}", UserName, Password);
Shell.Current.GoToAsync("HomeView");
}
}

28
Views/HomeView.xaml Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:autosos_maui.ViewModels"
x:DataType="viewmodels:HomeViewModel"
x:Class="autosos_maui.Views.HomeView">
<ContentPage.Content>
<VerticalStackLayout Background="#F3F3F3">
<StackLayout Orientation="Vertical" Padding="20">
<StackLayout Orientation="Horizontal" VerticalOptions="Center">
<Label Text="接单中" WidthRequest="200" HeightRequest="50" VerticalOptions="Center" FontSize="20"></Label>
<Switch IsToggled="{Binding IsToggled,Mode=TwoWay}"></Switch>
<Label Text="|" WidthRequest="20" HeightRequest="20" TextColor="#BFBFBF"></Label>
<StackLayout HorizontalOptions="End" Orientation="Vertical">
<Image Source="order_receiving_start.png" IsVisible="{Binding IsToggled}" HeightRequest="30" WidthRequest="30"/>
<Image Source="order_receiving_end.png" IsVisible="{Binding IsToggled,Converter={StaticResource BoolNegationConverter}}" HeightRequest="30" WidthRequest="30"/>
<Label Text="订单" HorizontalOptions="Center"></Label>
</StackLayout>
</StackLayout>
</StackLayout>
<Grid></Grid>
</VerticalStackLayout>
</ContentPage.Content>
</ContentPage>

19
Views/HomeView.xaml.cs Normal file
View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using autosos_maui.ViewModels;
namespace autosos_maui.Views;
public partial class HomeView : ContentPage
{
private readonly HomeViewModel _homeViewModel;
public HomeView(HomeViewModel homeViewModel)
{
BindingContext = _homeViewModel = homeViewModel;
InitializeComponent();
}
}