概述- 登录窗体无论在bs还是cs中都很常见,使用winform或者wpf ui进行设计都相对比较简单,但是如果在WPF框架,比如:Caliburn.Micro下,设计一个符合MVVM思想的登录窗体就相对有了点难度,因为CM框架本身的设计理念是VM first而非View first.接下来开始讲解我的设计.
后台设计前台设计全部代码如下:
<Window x:Class="Caliburn.Micro.Hello.LoginView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:dxe="http://schemas./winfx/2008/xaml/editors" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas./markup-compatibility/2006" mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Background="{x:Null}" Title="LoginWindow" Height="320" Width="300" WindowStartupLocation="CenterScreen"> <Grid Width="{Binding Width, ElementName=w}" Height="{Binding Height, ElementName=w}"> <Grid.RowDefinitions> <RowDefinition Height="150" /> <RowDefinition Height="50" /> <RowDefinition Height="50" /> <RowDefinition /> </Grid.RowDefinitions> <Border Grid.RowSpan="4" BorderBrush="Gray" BorderThickness="3" CornerRadius="20" Margin="10" Opacity="1" Background="White"></Border> <Button Name="BtnClose" Grid.Row="0" Margin="20" Width="48" Height="48" BorderBrush="{x:Null}" Background="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top"> <Image Source="/Images/exit1.png"/> </Button> <Image Grid.Row="0" VerticalAlignment="Center" Width="120" Height="120" Source="/Images/login.png" />
<TextBox x:Name="UserTextBox" Text="{Binding UserInformation.UserName}" Grid.Row="1" Width="200" VerticalAlignment="Bottom" BorderThickness="0,0,0,1" Height="25"></TextBox> <TextBlock Foreground="DarkGray" Grid.Row="1" IsHitTestVisible="False" HorizontalAlignment="Center" Height="25" Text="请输入用户名" VerticalAlignment="Bottom" Width="90" FontFamily="Microsoft YaHei"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Setter Property="Visibility" Value="Collapsed"/> <Style.Triggers> <DataTrigger Binding="{Binding Text, ElementName=UserTextBox}" Value=""> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> <dxe:PasswordBoxEdit x:Name="PwdTextBox" Text="{Binding UserInformation.Password}" Grid.Row="2" Width="200" VerticalAlignment="Bottom" BorderThickness="0,0,0,1" Height="25"></dxe:PasswordBoxEdit> <TextBlock Foreground="DarkGray" Grid.Row="2" IsHitTestVisible="False" HorizontalAlignment="Center" Height="25" Text="请输入密码" VerticalAlignment="Bottom" Width="90" FontFamily="Microsoft YaHei"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Setter Property="Visibility" Value="Collapsed"/> <Style.Triggers> <DataTrigger Binding="{Binding Text, ElementName=PwdTextBox}" Value=""> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock>
<Button Name="BtnLogin" Grid.Row="2" Width="48" Margin="0,0,20,0" BorderBrush="{x:Null}" Background="{x:Null}" Height="48" HorizontalAlignment="Right" VerticalAlignment="Top"> <Image Source="/Images/userlogin.png"/> </Button> </Grid> </Window>
效果演示![](http://image109.360doc.com/DownloadImg/2022/03/1912/241416898_1_20220319123624128.gif)
源码提取项目下载下来先还原包,得联网的奥,确保引用的地方没有黄色感叹号,此项目还引用了几个dev的库,确保dev已经安装。
|