WPF实现登录页面设计

news2024/11/17 7:38:45

1、文件架构
在这里插入图片描述

2、CommandBase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace CourseManagement.Common
{
    public class CommandBase : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return DoCanExecute?.Invoke(parameter)==true;
        }

        public void Execute(object parameter)
        {
            DoExecute?.Invoke(parameter);
        }

        public Action<object> DoExecute { get; set; }

        public Func<object,bool> DoCanExecute {  get; set; }
    }
}

3、NotifyBase.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace CourseManagement.Common
{
    public class NotifyBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void DoNotify([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(propertyName));
        }
    }
}

4、PasswordHelper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace CourseManagement.Common
{
    public class PasswordHelper
    {
        public static readonly DependencyProperty PasswordProperty=
            DependencyProperty.RegisterAttached("Password",typeof(string),typeof(PasswordHelper),
                new PropertyMetadata("",new PropertyChangedCallback(OnPropertyChanged)));

        public static string GetPassword(DependencyObject d)
        {
            return (string)d.GetValue(PasswordProperty);
        }

        public static void SetPassword(DependencyObject d, string value)
        {
            d.SetValue(PasswordProperty,value);
        }

        public static readonly DependencyProperty AttachProperty =
            DependencyProperty.RegisterAttached("Attach", typeof(bool), typeof(PasswordHelper),
                new PropertyMetadata(default(bool), new PropertyChangedCallback(OnAttached)));

        public static bool GetAttach(DependencyObject d)
        {
            return (bool)d.GetValue(AttachProperty);
        }

        public static void SetAttach(DependencyObject d, string value)
        {
            d.SetValue(AttachProperty, value);
        }

        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PasswordBox passwordBox=d as PasswordBox;
            passwordBox.PasswordChanged -= Password_PasswordChanged;
            if (!_isUpdating)
            {
                passwordBox.Password = e.NewValue?.ToString();
            }
            passwordBox.PasswordChanged += Password_PasswordChanged;
        }

        private static void OnAttached(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PasswordBox passwordBox = d as PasswordBox;
            passwordBox.PasswordChanged += Password_PasswordChanged;
        }

        private static bool _isUpdating = false;
        private static void Password_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = sender as PasswordBox;
            _isUpdating = true;
            SetPassword(passwordBox, passwordBox.Password);
            _isUpdating=false;
        }
    }
}

5、LoginModel.cs

using CourseManagement.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CourseManagement.Model
{
    public class LoginModel:NotifyBase
    {
		private string _userName;
		public string UserName
		{
			get { return _userName; }
			set { _userName = value; this.DoNotify();}
		}

		private string _password;
		public string Password
		{
			get { return _password; }
			set { _password = value; this.DoNotify();}
		}

		private string _validationCode;
		public string ValidationCode
		{
			get { return _validationCode; }
			set { _validationCode = value; this.DoNotify();}
		}

	}
}

6、LoginView.xaml

<Window x:Class="CourseManagement.View.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CourseManagement.View"
        xmlns:common="clr-namespace:CourseManagement.Common"
        mc:Ignorable="d"
        Title="系统登录" Height="600" Width="360"
        FontFamily="Microsoft YaHei" FontWeight="ExtraLight"
        ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
        WindowStyle="None" AllowsTransparency="True" Background="{x:Null}"
        Name="LoginWindow"
        >
    <Window.Resources>
        <ControlTemplate TargetType="Button" x:Key="CLoseButtonTemplate">
            <Border Background="Transparent" Name="Back">
                <Path Data="M0,0 12,12 M0,12 12,0" Stroke="White" StrokeThickness="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="Back" Property="Background" Value="#22FFFF"/>
                </Trigger>
                <Trigger Property="IsPressed" Value="true">
                    <Setter TargetName="Back" Property="Background" Value="#FF22FF"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <ControlTemplate TargetType="Button" x:Key="LoginButtonTemplate">
            <Border Background="#007DFA" CornerRadius="5">
                <Grid>
                    <Border CornerRadius="4" Background="#22ffffff" Name="Back" Visibility="Hidden"/>
                    <ContentControl Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center"
                                Foreground="{TemplateBinding Foreground}"/>
                </Grid>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Visibility" Value="Visible" TargetName="Back"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        
        <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
        <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
        <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
        <Style x:Key="UserNameTextBoxStyle" TargetType="{x:Type TextBox}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"
                                CornerRadius="5">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="40"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="&#xe7ae;" FontFamily="../Assets/Fonts/#iconfont" FontSize="20"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#DDD"/>
                                <ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="false" HorizontalScrollBarVisibility="Hidden" 
                                              VerticalScrollBarVisibility="Hidden"
                                              VerticalAlignment="Center" MinHeight="20"/>
                            </Grid>
                            
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
                        <Condition Property="IsSelectionActive" Value="false"/>
                    </MultiTrigger.Conditions>
                    <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
                </MultiTrigger>
            </Style.Triggers>
        </Style>
        <SolidColorBrush x:Key="TextBox.Static.Border1" Color="#FFABAdB3"/>
        <SolidColorBrush x:Key="TextBox.MouseOver.Border1" Color="#FF7EB4EA"/>
        <SolidColorBrush x:Key="TextBox.Focus.Border1" Color="#FF569DE5"/>
        <Style x:Key="PasswordBoxStyle" TargetType="{x:Type PasswordBox}">
            <Setter Property="PasswordChar" Value="●"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border1}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type PasswordBox}">
                        <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"
                                CornerRadius="5">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="40"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="&#xe90c;" FontFamily="../Assets/Fonts/#iconfont" FontSize="20"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#DDD"/>
                                <ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="false" HorizontalScrollBarVisibility="Hidden" 
                                              VerticalScrollBarVisibility="Hidden"
                                              VerticalAlignment="Center" MinHeight="20"/>
                            </Grid>
                            
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border1}"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border1}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
                        <Condition Property="IsSelectionActive" Value="false"/>
                    </MultiTrigger.Conditions>
                    <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
                </MultiTrigger>
            </Style.Triggers>
        </Style>
        <SolidColorBrush x:Key="TextBox.Static.Border2" Color="#FFABAdB3"/>
        <SolidColorBrush x:Key="TextBox.MouseOver.Border2" Color="#FF7EB4EA"/>
        <SolidColorBrush x:Key="TextBox.Focus.Border2" Color="#FF569DE5"/>
        <Style x:Key="ValidationCodeTextBoxStyle" TargetType="{x:Type TextBox}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border2}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"
                                CornerRadius="5">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="40"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="80"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="&#xe6ba;" FontFamily="../Assets/Fonts/#iconfont" FontSize="20"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#DDD"/>
                                <ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="false" HorizontalScrollBarVisibility="Hidden" 
                                              VerticalScrollBarVisibility="Hidden"
                                              VerticalAlignment="Center" MinHeight="20"/>
                                <Image Grid.Column="2" Source="../Assets/Validation/V0480.png" VerticalAlignment="Center" HorizontalAlignment="Center"
                                       Opacity="0.5"/>
                            </Grid>

                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border2}"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border2}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
                        <Condition Property="IsSelectionActive" Value="false"/>
                    </MultiTrigger.Conditions>
                    <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
                </MultiTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Border Margin="5" Background="White" CornerRadius="10">
        <Border.Effect>
            <DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"/>
        </Border.Effect>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="1.8*"/>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="80"/>
            </Grid.RowDefinitions>
            <!--1行Log-->
            <Border Background="#007DFA" CornerRadius="10 10 0 0" MouseLeftButtonDown="WinMove_MouseLeftButtonDown"/>
            <Button VerticalAlignment="Top" HorizontalAlignment="Right" Width="30" Height="30"
                    Template="{StaticResource CLoseButtonTemplate}"
                    Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=LoginWindow}"/>
            <StackPanel VerticalAlignment="Bottom" Margin="0 0 0 20">
                <Border Width="100" Height="100" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" CornerRadius="5">
                    <Border.Effect>
                        <DropShadowEffect Color="white" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"/>
                    </Border.Effect>
                    <Border Width="80" Height="80">
                        <Border.Background>
                            <ImageBrush ImageSource="../Assets/Images/Logo.png"/>
                        </Border.Background>
                    </Border>
                </Border>
                <TextBlock Text="大浪淘沙" HorizontalAlignment="Center" FontSize="20" Foreground="White"/>
            </StackPanel>
            <!--2行登录-->
            <Grid Grid.Row="1" Margin="20 20">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition MinHeight="23" Height="auto"/>
                </Grid.RowDefinitions>
                <TextBox Text="{Binding LoginModel.UserName}" Style="{DynamicResource UserNameTextBoxStyle}" FontSize="16" Foreground="#555" Height="40"/>
                <PasswordBox Style="{DynamicResource PasswordBoxStyle}" Grid.Row="1" FontSize="16" Foreground="#555" Height="40" 
                             common:PasswordHelper.Attach="True" common:PasswordHelper.Password="{Binding LoginModel.Password,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
                <TextBox Text="{Binding LoginModel.ValidationCode}" Style="{DynamicResource ValidationCodeTextBoxStyle}" Grid.Row="2" Height="40"/>
                <Button Template="{StaticResource LoginButtonTemplate}" Content="登录" Grid.Row="3" Height="40" Foreground="White"
                        FontSize="16" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=LoginWindow}"/>
                <TextBlock Text="{Binding ErrorMessage}" Grid.Row="4" Foreground="Red" FontSize="16" TextWrapping="Wrap" LineHeight="22"/>
            </Grid>
            <!--3行其它方式-->
            <Grid Grid.Row="2" Margin="20 0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="20"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Border BorderBrush="#DDD" BorderThickness="0 0 0 1" VerticalAlignment="Center"/>
                    <TextBlock Text="OR" Grid.Column="1" Foreground="#DDD" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    <Border Grid.Column="2" BorderBrush="#DDD" BorderThickness="0 0 0 1" VerticalAlignment="Center"/>
                </Grid>
                <UniformGrid Columns="3" Grid.Row="1">
                    <UniformGrid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="HorizontalAlignment" Value="Center"/>
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="Foreground" Value="#DDD"/>
                            <Setter Property="FontFamily" Value="../Assets/Fonts/#iconfont"/>
                            <Setter Property="FontSize" Value="40"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Foreground" Value="#007DFA"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </UniformGrid.Resources>
                    <TextBlock Text="&#xe887;"/>
                    <TextBlock Text="&#xe619;"/>
                    <TextBlock Text="&#xe625;"/>
                </UniformGrid>
            </Grid>
        </Grid>
    </Border>
</Window>

7、LoginView.xaml.cs

using CourseManagement.Model;
using CourseManagement.ViewModel;
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.Shapes;

namespace CourseManagement.View
{
    /// <summary>
    /// LoginView.xaml 的交互逻辑
    /// </summary>
    public partial class LoginView : Window
    {

        public LoginView()
        {
            InitializeComponent();
            this.DataContext = new LoginViewModel();
        }

        private void WinMove_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if(e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }
    }
}

8、MainView.xaml

<Window x:Class="CourseManagement.View.MainView"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CourseManagement"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        
    </Grid>
</Window>

9、MainView.xaml.cs

namespace CourseManagement.View
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        public MainView()
        {
            InitializeComponent();
        }
    }
}

10、LoginViewModel.cs

using CourseManagement.Common;
using CourseManagement.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CourseManagement.ViewModel
{
    public class LoginViewModel:NotifyBase
    {
        public LoginModel LoginModel { get; set; }=new LoginModel();
        public CommandBase CloseWindowCommand { get; set; }
        public CommandBase LoginCommand { get; set; }

        private string _errorMessage;

        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; this.DoNotify(); }
        }


        public LoginViewModel() 
        {
            //this.LoginModel = new LoginModel();
            //this.LoginModel.UserName = "Tiger";
            //this.LoginModel.Password = "123456";

            this.CloseWindowCommand = new CommandBase();
            this.CloseWindowCommand.DoExecute = new Action<object>((o) =>
            {
                (o as Window).Close();
            });
            this.CloseWindowCommand.DoCanExecute=new Func<object, bool>((o) => { return true; });

            this.LoginCommand=new CommandBase();
            this.LoginCommand.DoExecute = new Action<object>(DoLogin);
            this.LoginCommand.DoCanExecute = new Func<object, bool>((o) => { return true; });

        }

        private void DoLogin(object o)
        {
            this.ErrorMessage = "";
            if (string.IsNullOrEmpty(LoginModel.UserName))
            {
                this.ErrorMessage = "请输入用户名!";
                return;
            }
            if (string.IsNullOrEmpty(LoginModel.Password))
            {
                this.ErrorMessage = "请输入密码!";
                return;
            }
            if (string.IsNullOrEmpty(LoginModel.ValidationCode))
            {
                this.ErrorMessage = "请输入验证码!";
                return;
            }
            if (LoginModel.ValidationCode.ToLower() != "0480")
            {
                this.ErrorMessage = "验证码输入不正确!";
                return;
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                (o as Window).DialogResult = true;
            }));
            
        }

    }
}

11、App.xaml

<Application x:Class="CourseManagement.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:CourseManagement"
             ShutdownMode="OnExplicitShutdown">
    <Application.Resources>
         
    </Application.Resources>
</Application>

12、App.xaml.cs

using CourseManagement.View;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace CourseManagement
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            if(new LoginView().ShowDialog() == true)
            {
                new MainView().ShowDialog();
            }
            Application.Current.Shutdown();
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/687751.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

EXCEL和VBA如何改变字母大小写 和 大小写互换?我写的自定义函数

目录 1 EXCEL里改变大小写的内置函数 2.1 转换大小写的函数 2.2 神奇的把数字和中文大小写转换的函数 2 VBA里改变大小写的内置函数 2.1 改变大小写 的内置函数 2.2 使用 excel的WorksheetFunction. text() 函数 3 如果想交换字母的大小写呢&#xff1f; 3.1 ASCII码里…

Java Servlet 技术

一、Servlet 简介 Servlet 是 JavaEE 的规范之一&#xff0c;通俗的来说就是 Java 接口&#xff0c;将来我们可以定义 Java 类来实现这个接口&#xff0c;并由 Web 服务器运行 Servlet &#xff0c;所以 TomCat 又被称作 Servlet 容器。 Servlet 提供了动态 Web 资源开发技术…

偷偷爆料下工资特别高的8个开发岗。。。。。

外国网站 devjobsscanner 统计了全年需求量大的8种编程语言&#xff0c;基本上薪资很高的&#xff0c;也就是这几个方向了。 对于跳槽、找工作、转行、转语言等&#xff0c;都有一定的参考意义。 接下来结合网站统计和招聘网站的数据&#xff0c;可以做一个对照。 NO.1 Java…

MongoDB的基本操作

MongoDB的基本操作 MongoDB MongoDB是一个基于分布式文件存储的数据库&#xff0c;由C语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是一个介于关系数据库和非关系数据库之间的产品&#xff0c;是非关系数据库当中功能最丰富&#xff0c;最像关系数…

游泳带什么防水耳机好,最佳游泳耳机的推荐排行榜

在炎炎夏日&#xff0c;玩水无疑是降温的最佳方式。既可以在室内游泳馆通过游泳锻炼身体&#xff0c;也可以到海滨浴场享受游泳和日光浴的乐趣。因此&#xff0c;选购一款适合水上活动的游泳耳机变得尤为重要。音乐的力量可以让原本单调乏味的游泳运动变得更具活力&#xff0c;…

Linux基础服务4——ftp

文章目录 一、基本了解1.1 C/S型架构1.2 数据连接模式1.3 用户认证 二、安装服务端2.1 安装vsftpd2.2 配置文件2.3 主配置文件参数2.4 windows访问服务端2.4.1 系统用户访问2.4.2 匿名用户访问2.4.2 开启客户端上传权限2.4.3 开启客户端其他权限2.4.4 开启客户端删除、修改权限…

hvv 文件上传和文件包含考点

天眼如何判断文件上传漏洞是否成功 数据包分析 观察客户端请求数据&#xff1a;是否包含webshell流量特征观察服务器返回信息&#xff1a;是否有“上传成功”或“success upload”等信息提示 尝试寻找上传的文件&#xff1a;访问上传的文件看是否存在&#xff1b;查看文件上传…

Redisson分布式锁-源码分析

Redisson分布式锁整体流程图 Redisson分布式锁源码流程图 Redisson分布式锁源码解析 获取分布式锁lock private void lock(long leaseTime, TimeUnit unit, boolean interruptibly) throws InterruptedException {//获取当前线程IDlong threadId Thread.currentThread().get…

参与 2023 第二季度官方 Flutter 开发者调查

Flutter 3.10 已经正式发布&#xff0c;每个季度一次的 Flutter 开发者调查也来啦&#xff01;邀请社区的各位成员们填写&#xff1a; 调研旨在了解你对 Flutter 的满意程度以及对其各个子系统的反馈。你的意见将对我们改进 Flutter 的功能和性能产生重要影响。 在这次调研中&a…

Linux——软硬链接的理解

目录 那什么是链接&#xff1f; 链接命令的生成&#xff1a; 实验案例&#xff1a; 硬链接概念&#xff1a; 软链接概念&#xff1a; 情况1&#xff1a;删除myfile.txt&#xff1a; 情况2&#xff1a;重新创建一个新的myfile.txt文件&#xff1a; 软链接作用&#xff1…

推特引流:社交引流的技巧与方法

推特是一个广泛使用的社交媒体平台&#xff0c;可以用于引流和推广您的品牌、产品或服务。以下是一些社交引流的技巧和方法&#xff0c;可以帮助您在推特上获得更多的关注和流量&#xff1a; 优化个人资料&#xff1a;确保您的推特个人资料完整并具有吸引力。包括一个清晰的头…

yolov8-02 训练自己的数据集

1. 准备数据集 数据集格式跟yolov5一样&#xff0c;关于如何准备数据集可见之前的文章。 2. 创建 mydata.yaml 格式参考coco128.yaml&#xff0c;主要是 train / validate文件的存放路径&#xff0c;可以是同一个。 在ultralytics-main/ultralytics/datasets中&#xff0c;…

【Linux】ubuntu20.04安装ansys2023r1教程--超详细

一、安装包及其和谐文件 双击挂载 二、在ubuntu上安装依赖项 执行命令sudo apt install build-essential xterm libmotif-dev libxtst-dev libxt-dev libzip-dev libxmu-dev tcl tk lsb csh xfonts-75dpi xfonts-100dpi wine 弹出一个提示&#xff0c;需要去下载一个171MB的压…

Simulink 中基于 FPGA 的波束成形:算法设计(附源码)

一、前言 本示例显示了在 Simulink中开发适用于在硬件&#xff08;如现场可编程门阵列 &#xff08;FPGA&#xff09;&#xff09;上实现的波束成形器的工作流程的前半部分。它还演示如何将实现模型的结果与行为模型的结果进行比较。 示例 Simulink 中基于 FPGA 的波束成形&…

shell 数组 ${array[@]} ${array[*]}的使用及区别

数组定义 shell中用括号来表示数组&#xff0c;数组元素间使用空格隔开。 例如&#xff1a; a(1 2 3 4) 表示a数组且有元素为1,2,3,4 也可单个元素逐步来赋值 b[1]"a" b[2]"b" b[3]"c" echo ${b[]} # a b c 关联数组 定义关联数组&#xf…

论文翻译:Segment Anything

论文地址&#xff1a;https://arxiv.org/abs/2304.02643 代码地址&#xff1a;https://github.com/facebookresearch/segment-anything 数据集地址&#xff1a;https://ai.facebook.com/datasets/segment-anything/ “Segment Anything"项目旨在通过引入新的任务、数据集…

决定AI大模型胜负的关键:解读数据在未来竞争中的角色

随着人工智能的迅猛发展&#xff0c;高质量数据的重要性已愈发明显。以大型语言模型为例&#xff0c;近年来的飞跃式进展在很大程度上依赖于高质量和丰富的训练数据集。相比于GPT-2&#xff0c;GPT-3在模型架构上的改变微乎其微&#xff0c;更大的精力是投入到了收集更大、更高…

声卡设备无法正常工作或初始化的原因和解决方法

先来一个小科普&#xff0c;声卡设备是电脑中负责处理音频信号的硬件部件&#xff0c;它需要与相应的声卡驱动程序配合使用&#xff0c;才能让电脑发出或录制声音。 不过&#xff0c;自带声卡的设备或是自行匹配的声卡设备&#xff0c;也经常出现声卡设备无法正常工作或初始化…

通过Jenkins实现Unity多平台自动打包以及相关问题解决

简介 通过本文可以了解到如何在windows和mac上部署Jenkins。并且通过Jenkins实现Unity在IOS,安卓和PC等多平台自动打包的功能&#xff0c;并且可以将打包结果通过飞书机器人同步到飞书群内。优化工作流&#xff0c;提高团队的开发效率。文末记录了实际使用Jenkins时遇到的各种问…

Leetcode44 通配符匹配

给你一个输入字符串 (s) 和一个字符模式 (p) &#xff0c;请你实现一个支持 ? 和 * 匹配规则的通配符匹配&#xff1a; ? 可以匹配任何单个字符。 * 可以匹配任意字符序列&#xff08;包括空字符序列&#xff09;。 判定匹配成功的充要条件是&#xff1a;字符模式必须能够 完…