添加的登录界面,使用固定账号和密码测试登录逻辑成功
This commit is contained in:
20
WorkStation.Client/App.xaml
Normal file
20
WorkStation.Client/App.xaml
Normal file
@ -0,0 +1,20 @@
|
||||
<prism:PrismApplication
|
||||
x:Class="WorkStation.Client.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WorkStation.Client"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<materialDesign:BundledTheme
|
||||
BaseTheme="Light"
|
||||
PrimaryColor="DeepPurple"
|
||||
SecondaryColor="Lime" />
|
||||
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</prism:PrismApplication>
|
37
WorkStation.Client/App.xaml.cs
Normal file
37
WorkStation.Client/App.xaml.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Prism.Ioc;
|
||||
using Prism.Services.Dialogs;
|
||||
using System.Windows;
|
||||
using WorkStation.Client.ViewModels.Dialogs;
|
||||
using WorkStation.Client.Views;
|
||||
using WorkStation.Client.Views.Dialogs;
|
||||
|
||||
namespace WorkStation.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App
|
||||
{
|
||||
protected override Window CreateShell()
|
||||
{
|
||||
return Container.Resolve<MainWindow>();
|
||||
}
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var dialogService = Container.Resolve<IDialogService>();
|
||||
dialogService.ShowDialog("LoginView", result =>
|
||||
{
|
||||
if (result.Result == ButtonResult.OK)
|
||||
{
|
||||
base.OnInitialized();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
BIN
WorkStation.Client/Images/LoginImage.png
Normal file
BIN
WorkStation.Client/Images/LoginImage.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 MiB |
90
WorkStation.Client/ViewModels/Dialogs/LoginViewModel.cs
Normal file
90
WorkStation.Client/ViewModels/Dialogs/LoginViewModel.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using Prism.Services.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WorkStation.Client.ViewModels.Dialogs
|
||||
{
|
||||
public class LoginViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
/// <summary>
|
||||
/// 弹窗标题
|
||||
/// </summary>
|
||||
public string Title => "登录界面";
|
||||
|
||||
/// <summary>
|
||||
/// 账户
|
||||
/// </summary>
|
||||
private string _account = string.Empty;
|
||||
public string Account
|
||||
{
|
||||
get => _account;
|
||||
set => SetProperty(ref _account, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
private string _password = string.Empty;
|
||||
public string Password
|
||||
{
|
||||
get => _password;
|
||||
set => SetProperty(ref _password, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于关闭窗口时,判断是否登录成功。
|
||||
/// 如果登录失败就终止当前应用。
|
||||
/// </summary>
|
||||
private bool _isSuccess = false;
|
||||
|
||||
/// <summary>
|
||||
/// 登录名利
|
||||
/// </summary>
|
||||
public DelegateCommand LoginCommand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求关闭委托
|
||||
/// </summary>
|
||||
public event Action<IDialogResult> RequestClose;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the dialog can be closed.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the dialog can be closed; otherwise, <see langword="false"/>.</returns>
|
||||
public bool CanCloseDialog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
if (_isSuccess == false)
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
public LoginViewModel()
|
||||
{
|
||||
LoginCommand = new DelegateCommand(() =>
|
||||
{
|
||||
if (Account == "11" && Password == "22")
|
||||
{
|
||||
_isSuccess = true;
|
||||
RequestClose(new DialogResult(ButtonResult.OK));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
19
WorkStation.Client/ViewModels/MainWindowViewModel.cs
Normal file
19
WorkStation.Client/ViewModels/MainWindowViewModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace WorkStation.Client.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel : BindableBase
|
||||
{
|
||||
private string _title = "Prism Application";
|
||||
public string Title
|
||||
{
|
||||
get { return _title; }
|
||||
set { SetProperty(ref _title, value); }
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
47
WorkStation.Client/Views/Dialogs/LoginView.xaml
Normal file
47
WorkStation.Client/Views/Dialogs/LoginView.xaml
Normal file
@ -0,0 +1,47 @@
|
||||
<UserControl
|
||||
x:Class="WorkStation.Client.Views.Dialogs.LoginView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WorkStation.Client.Views.Dialogs"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Width="800"
|
||||
Height="450"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.5*" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image
|
||||
Grid.Column="0"
|
||||
Margin="10"
|
||||
Source="/Images/LoginImage.png" />
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="50"
|
||||
Text="登录" />
|
||||
<TextBlock
|
||||
FontSize="20"
|
||||
Text="账号" />
|
||||
<TextBox
|
||||
Width="200"
|
||||
Margin="5"
|
||||
Text="{Binding Account}" />
|
||||
<TextBlock
|
||||
FontSize="20"
|
||||
Text="密码" />
|
||||
<TextBox
|
||||
Width="200"
|
||||
Margin="5"
|
||||
Text="{Binding Password}" />
|
||||
<Button
|
||||
Command="{Binding LoginCommand}"
|
||||
Content="登录" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
28
WorkStation.Client/Views/Dialogs/LoginView.xaml.cs
Normal file
28
WorkStation.Client/Views/Dialogs/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 WorkStation.Client.Views.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LoginView.xaml
|
||||
/// </summary>
|
||||
public partial class LoginView : UserControl
|
||||
{
|
||||
public LoginView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
13
WorkStation.Client/Views/MainWindow.xaml
Normal file
13
WorkStation.Client/Views/MainWindow.xaml
Normal file
@ -0,0 +1,13 @@
|
||||
<Window
|
||||
x:Class="WorkStation.Client.Views.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
Title="{Binding Title}"
|
||||
Width="525"
|
||||
Height="350"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True">
|
||||
<Grid>
|
||||
<Button />
|
||||
</Grid>
|
||||
</Window>
|
15
WorkStation.Client/Views/MainWindow.xaml.cs
Normal file
15
WorkStation.Client/Views/MainWindow.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace WorkStation.Client.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
17
WorkStation.Client/WorkStation.Client.csproj
Normal file
17
WorkStation.Client/WorkStation.Client.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Images\LoginImage.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MaterialDesignThemes" Version="5.2.1" />
|
||||
<PackageReference Include="Prism.DryIoc" Version="8.1.97" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Images\LoginImage.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user