模块化
This commit is contained in:
21
LoginModule/LoginModule.cs
Normal file
21
LoginModule/LoginModule.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using LoginModule.Views;
|
||||
using Prism.Modularity;
|
||||
using System.Reflection;
|
||||
namespace LoginModule
|
||||
{
|
||||
public class LoginModule : IModule
|
||||
{
|
||||
public void OnInitialized(IContainerProvider containerProvider)
|
||||
{
|
||||
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
|
||||
regionManager.RegisterViewWithRegion("LoginRegion", typeof(LoginView));
|
||||
regionManager.RegisterViewWithRegion("LoginRegion", typeof(RegisterView));
|
||||
}
|
||||
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterForNavigation<LoginView>("LoginView");
|
||||
containerRegistry.RegisterForNavigation<RegisterView>("RegisterView");
|
||||
}
|
||||
}
|
||||
}
|
||||
12
LoginModule/LoginModule.csproj
Normal file
12
LoginModule/LoginModule.csproj
Normal file
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UIShare\UIShare.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
48
LoginModule/ViewModels/LoginViewModel.cs
Normal file
48
LoginModule/ViewModels/LoginViewModel.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace LoginModule.ViewModels
|
||||
{
|
||||
public class LoginViewModel: NavigateViewModelBase
|
||||
{
|
||||
#region 属性
|
||||
private string _Password;
|
||||
public string Password
|
||||
{
|
||||
get => _Password;
|
||||
set => SetProperty(ref _Password, value);
|
||||
}
|
||||
private string _Account;
|
||||
public string Account
|
||||
{
|
||||
get => _Account;
|
||||
set => SetProperty(ref _Account, value);
|
||||
}
|
||||
#endregion
|
||||
public ICommand LoginCommand { get; set; }
|
||||
public ICommand RegisterCommand { get; set; }
|
||||
private IEventAggregator _eventAggregator;
|
||||
public LoginViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
||||
LoginCommand = new AsyncDelegateCommand(OnLogin);
|
||||
RegisterCommand = new AsyncDelegateCommand(OnRegister);
|
||||
}
|
||||
|
||||
private async Task OnRegister()
|
||||
{
|
||||
_regionManager.RequestNavigate("LoginRegion", "RegisterView");
|
||||
}
|
||||
|
||||
private async Task OnLogin()
|
||||
{
|
||||
_eventAggregator.GetEvent<LoginSuccessEvent>().Publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
51
LoginModule/ViewModels/RegisterViewModel.cs
Normal file
51
LoginModule/ViewModels/RegisterViewModel.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace LoginModule.ViewModels
|
||||
{
|
||||
public class RegisterViewModel : NavigateViewModelBase
|
||||
{
|
||||
#region 属性
|
||||
private string _SecondPassword;
|
||||
public string SecondPassword
|
||||
{
|
||||
get => _SecondPassword;
|
||||
set => SetProperty(ref _SecondPassword, value);
|
||||
}
|
||||
private string _Password;
|
||||
public string Password
|
||||
{
|
||||
get => _Password;
|
||||
set => SetProperty(ref _Password, value);
|
||||
}
|
||||
private string _Account;
|
||||
public string Account
|
||||
{
|
||||
get => _Account;
|
||||
set => SetProperty(ref _Account, value);
|
||||
}
|
||||
#endregion
|
||||
public ICommand BackCommand { get; set; }
|
||||
public ICommand RegisterCommand { get; set; }
|
||||
public RegisterViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
BackCommand = new DelegateCommand(OnBack);
|
||||
RegisterCommand = new AsyncDelegateCommand(OnRegister);
|
||||
}
|
||||
|
||||
private void OnBack()
|
||||
{
|
||||
_regionManager.RequestNavigate("LoginRegion", "LoginView");
|
||||
}
|
||||
|
||||
private async Task OnRegister()
|
||||
{
|
||||
_regionManager.RequestNavigate("LoginRegion", "LoginView");
|
||||
}
|
||||
}
|
||||
}
|
||||
163
LoginModule/Views/LoginView.xaml
Normal file
163
LoginModule/Views/LoginView.xaml
Normal file
@@ -0,0 +1,163 @@
|
||||
<UserControl x:Class="LoginModule.Views.LoginView"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
xmlns:local="clr-namespace:LoginModule.Views"
|
||||
mc:Ignorable="d"
|
||||
Height="315"
|
||||
Width="420">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- 这里是你的额外样式 -->
|
||||
<Style TargetType="TextBox"
|
||||
BasedOn="{StaticResource MahApps.Styles.TextBox}">
|
||||
<Setter Property="FontSize"
|
||||
Value="14" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0,0,0,2" />
|
||||
<Setter Property="BorderBrush"
|
||||
Value="#E0E0E0" />
|
||||
<Setter Property="Padding"
|
||||
Value="5,8" />
|
||||
<Setter Property="Background"
|
||||
Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="PasswordBox"
|
||||
BasedOn="{StaticResource MahApps.Styles.PasswordBox}">
|
||||
<Setter Property="FontSize"
|
||||
Value="14" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0,0,0,2" />
|
||||
<Setter Property="BorderBrush"
|
||||
Value="#E0E0E0" />
|
||||
<Setter Property="Padding"
|
||||
Value="5,8" />
|
||||
<Setter Property="Background"
|
||||
Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Button"
|
||||
BasedOn="{StaticResource MahApps.Styles.Button.Flat}">
|
||||
<Setter Property="FontSize"
|
||||
Value="15" />
|
||||
<Setter Property="FontWeight"
|
||||
Value="SemiBold" />
|
||||
<Setter Property="Foreground"
|
||||
Value="White" />
|
||||
<Setter Property="Background"
|
||||
Value="#2196F3" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0" />
|
||||
<Setter Property="Margin"
|
||||
Value="0,20,0,0" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="40" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<Border Grid.Row="0"
|
||||
Background="White"
|
||||
Margin="20,20,20,0"
|
||||
CornerRadius="5"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#E0E0E0"
|
||||
Padding="30,20">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<Label Content="用户登录"
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="15"
|
||||
Padding="3" />
|
||||
<StackPanel Grid.Row="1">
|
||||
|
||||
<!-- 用户名输入 -->
|
||||
<StackPanel Orientation="Vertical"
|
||||
HorizontalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="17">
|
||||
<materialDesign:PackIcon Kind="Account"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding Account}"
|
||||
mah:TextBoxHelper.Watermark="请输入账号"
|
||||
mah:TextBoxHelper.ClearTextButton="True"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="180"
|
||||
Height="30"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 密码输入 -->
|
||||
<StackPanel Orientation="Vertical"
|
||||
HorizontalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="7">
|
||||
<materialDesign:PackIcon Kind="Lock"
|
||||
VerticalAlignment="Center" />
|
||||
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay}"
|
||||
mah:TextBoxHelper.Watermark="请输入密码"
|
||||
mah:TextBoxHelper.ClearTextButton="True"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="180"
|
||||
Height="30"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
<Label Content="注册账户"
|
||||
HorizontalAlignment="Right"
|
||||
Cursor="Hand">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeftButtonUp">
|
||||
<i:InvokeCommandAction Command="{Binding RegisterCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 登录按钮 -->
|
||||
<Button Grid.Row="2"
|
||||
Command="{Binding LoginCommand}"
|
||||
Content="登 录"
|
||||
Width="120"
|
||||
Height="33"
|
||||
mah:ControlsHelper.CornerRadius="5">
|
||||
<Button.Effect>
|
||||
<DropShadowEffect BlurRadius="8"
|
||||
ShadowDepth="3"
|
||||
Opacity="0.5" />
|
||||
</Button.Effect>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 底部版权信息 -->
|
||||
<TextBlock Grid.Row="2"
|
||||
Text="© 2025 大学生学习交流平台"
|
||||
Foreground="#777"
|
||||
FontSize="12"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,10" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
28
LoginModule/Views/LoginView.xaml.cs
Normal file
28
LoginModule/Views/LoginView.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace LoginModule.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// LoginView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class LoginView : UserControl
|
||||
{
|
||||
public LoginView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
175
LoginModule/Views/RegisterView.xaml
Normal file
175
LoginModule/Views/RegisterView.xaml
Normal file
@@ -0,0 +1,175 @@
|
||||
<UserControl x:Class="LoginModule.Views.RegisterView"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
xmlns:local="clr-namespace:LoginModule.Views"
|
||||
mc:Ignorable="d"
|
||||
Height="315"
|
||||
Width="420">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- 这里是你的额外样式 -->
|
||||
<Style TargetType="TextBox"
|
||||
BasedOn="{StaticResource MahApps.Styles.TextBox}">
|
||||
<Setter Property="FontSize"
|
||||
Value="14" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0,0,0,2" />
|
||||
<Setter Property="BorderBrush"
|
||||
Value="#E0E0E0" />
|
||||
<Setter Property="Padding"
|
||||
Value="5,8" />
|
||||
<Setter Property="Background"
|
||||
Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="PasswordBox"
|
||||
BasedOn="{StaticResource MahApps.Styles.PasswordBox}">
|
||||
<Setter Property="FontSize"
|
||||
Value="14" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0,0,0,2" />
|
||||
<Setter Property="BorderBrush"
|
||||
Value="#E0E0E0" />
|
||||
<Setter Property="Padding"
|
||||
Value="5,8" />
|
||||
<Setter Property="Background"
|
||||
Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Button"
|
||||
BasedOn="{StaticResource MahApps.Styles.Button.Flat}">
|
||||
<Setter Property="FontSize"
|
||||
Value="15" />
|
||||
<Setter Property="FontWeight"
|
||||
Value="SemiBold" />
|
||||
<Setter Property="Foreground"
|
||||
Value="White" />
|
||||
<Setter Property="Background"
|
||||
Value="#2196F3" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="0" />
|
||||
<Setter Property="Margin"
|
||||
Value="0,20,0,0" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="40" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<Border Grid.Row="0"
|
||||
Background="White"
|
||||
Margin="20,20,20,0"
|
||||
CornerRadius="5"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#E0E0E0"
|
||||
Padding="30,20">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<Label Content="用户注册"
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="15"
|
||||
Padding="3" />
|
||||
<StackPanel Grid.Row="1">
|
||||
|
||||
<!-- 用户名输入 -->
|
||||
<StackPanel Orientation="Vertical"
|
||||
HorizontalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="7">
|
||||
<materialDesign:PackIcon Kind="Account"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBox Text="{Binding Account}"
|
||||
mah:TextBoxHelper.Watermark="请输入账号"
|
||||
mah:TextBoxHelper.ClearTextButton="True"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="180"
|
||||
Height="30"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 密码输入 -->
|
||||
<StackPanel Orientation="Vertical"
|
||||
HorizontalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="7">
|
||||
<materialDesign:PackIcon Kind="Lock"
|
||||
VerticalAlignment="Center" />
|
||||
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay}"
|
||||
mah:TextBoxHelper.Watermark="请输入密码"
|
||||
mah:TextBoxHelper.ClearTextButton="True"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="180"
|
||||
Height="30"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="7">
|
||||
<materialDesign:PackIcon Kind="Lock"
|
||||
VerticalAlignment="Center" />
|
||||
<PasswordBox helpers:PasswordBoxHelper.Password="{Binding SecondPassword, Mode=TwoWay}"
|
||||
mah:TextBoxHelper.Watermark="请输入二次密码"
|
||||
mah:TextBoxHelper.ClearTextButton="True"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="180"
|
||||
Height="30"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
<Label Content="返回"
|
||||
HorizontalAlignment="Right"
|
||||
Cursor="Hand">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeftButtonUp">
|
||||
<i:InvokeCommandAction Command="{Binding BackCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 登录按钮 -->
|
||||
<Button Grid.Row="2"
|
||||
Command="{Binding RegisterCommand}"
|
||||
Content="注 册"
|
||||
Width="120"
|
||||
Height="33"
|
||||
mah:ControlsHelper.CornerRadius="5">
|
||||
<Button.Effect>
|
||||
<DropShadowEffect BlurRadius="8"
|
||||
ShadowDepth="3"
|
||||
Opacity="0.5" />
|
||||
</Button.Effect>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 底部版权信息 -->
|
||||
<TextBlock Grid.Row="2"
|
||||
Text="© 2025 大学生学习交流平台"
|
||||
Foreground="#777"
|
||||
FontSize="12"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,10" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
28
LoginModule/Views/RegisterView.xaml.cs
Normal file
28
LoginModule/Views/RegisterView.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace LoginModule.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// RegisterView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class RegisterView : UserControl
|
||||
{
|
||||
public RegisterView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user