添加登录界面UI
添加文件loginview.xaml。注意本界面使用的是md内的图标。没有登录界面的图片
<UserControl
x:Class="Mytodo.Views.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:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:Mytodo.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
mc:Ignorable="d">
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="Width" Value="600" />
<Setter Property="Height" Value="400" />
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
</Style>
</prism:Dialog.WindowStyle>
<Grid Width="350" Height="400">
<DockPanel Margin="15,5,15,20" VerticalAlignment="Center">
<md:PackIcon
Width="100"
Height="80"
HorizontalAlignment="Center"
VerticalAlignment="Center"
md:ThemeAssist.Theme="Dark"
DockPanel.Dock="Top"
Foreground="SpringGreen"
Kind="AccountOutline" />
<TextBlock
Margin="0,10"
DockPanel.Dock="Top"
FontSize="22"
FontWeight="Bold"
Text="欢迎使用" />
<TextBox
Margin="0,10"
md:HintAssist.Hint="请输入账号"
DockPanel.Dock="Top"
Text="{Binding UserName}" />
<PasswordBox
Margin="0,10"
md:HintAssist.Hint="请输入密码"
DockPanel.Dock="Top">
<!-- pass:PassWordExtensions.PassWord="{Binding PassWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" -->
<!--<i:Interaction.Behaviors>
<pass:PasswordBehavior />
</i:Interaction.Behaviors>-->
</PasswordBox>
<Button
Command="{Binding ExecuteCommand}"
CommandParameter="Login"
Content="登录系统"
DockPanel.Dock="Top" />
<DockPanel Margin="0,5" LastChildFill="False">
<TextBlock Text="注册账号">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding ExecuteCommand}" CommandParameter="ResgiterPage" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
<TextBlock DockPanel.Dock="Right" Text="忘记密码?" />
</DockPanel>
</DockPanel>
</Grid>
</UserControl>
添加对应的viewmodel
添加文件Mytodo.ViewModels.LoginViewModel.cs文章来源:https://www.toymoban.com/news/detail-622752.html
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mytodo.ViewModels
{
public class LoginViewModel : BindableBase, IDialogAware
{
public string Title { get; set; } = "TOdo";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
}
}
}
注册视图
containerRegistry.RegisterForNavigation<LoginView, LoginViewModel>();
添加启动
修改文件:App.xmal.cs文章来源地址https://www.toymoban.com/news/detail-622752.html
protected override void OnInitialized()
{
var dialog = Container.Resolve<IDialogService>();
dialog.ShowDialog("LoginView", callback =>
{
if (callback.Result != ButtonResult.OK)
{
Environment.Exit(0);
return;
}
var service = App.Current.MainWindow.DataContext as IConfigureInterface;
if (service != null)
{
service.Configure();
}
base.OnInitialized();
});
}
到了这里,关于WPF实战学习笔记28-登录界面的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!