From 85f34f27d72ddd086d4e3bc32122f97ae72b35ae Mon Sep 17 00:00:00 2001 From: zhuce <821293938@qq.com> Date: Fri, 29 Dec 2023 14:10:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MauiProgram.cs | 29 +++++++++++++++++++++++++++-- Resources/Styles/Colors.xaml | 2 +- Resources/Styles/Styles.xaml | 4 ++++ ViewModels/LoginViewModel.cs | 18 +++++++++++++++--- Views/LoginView.xaml | 33 ++++++++++++++++++++++++++------- Views/LoginView.xaml.cs | 6 +++++- autosos-maui.csproj | 1 - 7 files changed, 78 insertions(+), 15 deletions(-) diff --git a/MauiProgram.cs b/MauiProgram.cs index c236860..ce1540f 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -1,4 +1,6 @@ -using CommunityToolkit.Maui; +using autosos_maui.ViewModels; +using autosos_maui.Views; +using CommunityToolkit.Maui; using Microsoft.Extensions.Logging; namespace autosos_maui; @@ -15,7 +17,10 @@ public static class MauiProgram { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); - }); + }) + .RegisterViews() + .RegisterViewModels() + .RegisterAppServices(); #if DEBUG builder.Logging.AddDebug(); @@ -23,4 +28,24 @@ public static class MauiProgram return builder.Build(); } + + public static MauiAppBuilder RegisterViews(this MauiAppBuilder mauiAppBuilder) + { + mauiAppBuilder.Services.AddTransient(); + + return mauiAppBuilder; + } + + public static MauiAppBuilder RegisterViewModels(this MauiAppBuilder mauiAppBuilder) + { + mauiAppBuilder.Services.AddSingleton(); + + return mauiAppBuilder; + } + + public static MauiAppBuilder RegisterAppServices(this MauiAppBuilder mauiAppBuilder) + { + + return mauiAppBuilder; + } } \ No newline at end of file diff --git a/Resources/Styles/Colors.xaml b/Resources/Styles/Colors.xaml index 30307a5..d519624 100644 --- a/Resources/Styles/Colors.xaml +++ b/Resources/Styles/Colors.xaml @@ -6,7 +6,7 @@ - #512BD4 + #EB0E0E #ac99ea #242424 #DFD8F7 diff --git a/Resources/Styles/Styles.xaml b/Resources/Styles/Styles.xaml index e0d36bb..9ddd0ed 100644 --- a/Resources/Styles/Styles.xaml +++ b/Resources/Styles/Styles.xaml @@ -422,5 +422,9 @@ + + diff --git a/ViewModels/LoginViewModel.cs b/ViewModels/LoginViewModel.cs index 22a13cd..33ae16a 100644 --- a/ViewModels/LoginViewModel.cs +++ b/ViewModels/LoginViewModel.cs @@ -1,6 +1,18 @@ -namespace autosos_maui.ViewModels; +using System.Diagnostics; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; -public class LoginViewModel +namespace autosos_maui.ViewModels; + +public partial class LoginViewModel : ObservableObject { - + [ObservableProperty] private string _userName = ""; + [ObservableProperty] private string _password = ""; + + [RelayCommand] + public void Login() + { + Debug.WriteLine("login"); + Debug.WriteLine("username:{0},password:{1}",_userName,_password); + } } \ No newline at end of file diff --git a/Views/LoginView.xaml b/Views/LoginView.xaml index 7f98c98..ca66876 100644 --- a/Views/LoginView.xaml +++ b/Views/LoginView.xaml @@ -2,18 +2,37 @@ + x:Class="autosos_maui.Views.LoginView" + xmlns:viewmodels="clr-namespace:autosos_maui.ViewModels" + x:DataType="viewmodels:LoginViewModel"> - - + + - - - + + + - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Views/LoginView.xaml.cs b/Views/LoginView.xaml.cs index ce77f4e..ebc31da 100644 --- a/Views/LoginView.xaml.cs +++ b/Views/LoginView.xaml.cs @@ -3,13 +3,17 @@ 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 LoginView : ContentPage { - public LoginView() + private readonly LoginViewModel _viewModel; + + public LoginView(LoginViewModel loginViewModel) { + BindingContext = _viewModel = loginViewModel; InitializeComponent(); } } \ No newline at end of file diff --git a/autosos-maui.csproj b/autosos-maui.csproj index 4b9634f..1985b84 100644 --- a/autosos-maui.csproj +++ b/autosos-maui.csproj @@ -64,5 +64,4 @@ -