diff --git a/Helpers/PasswordBoxHelper.cs b/Helpers/PasswordBoxHelper.cs new file mode 100644 index 0000000..dcffdec --- /dev/null +++ b/Helpers/PasswordBoxHelper.cs @@ -0,0 +1,76 @@ +// PasswordBoxHelper.cs +using System.Windows; +using System.Windows.Controls; + +namespace VideoConcat.Helpers +{ + public static class PasswordBoxHelper + { + public static readonly DependencyProperty BoundPasswordProperty = + DependencyProperty.RegisterAttached("BoundPassword", typeof(string), typeof(PasswordBoxHelper), + new PropertyMetadata(string.Empty, OnBoundPasswordChanged)); + + public static readonly DependencyProperty BindPasswordProperty = + DependencyProperty.RegisterAttached("BindPassword", typeof(bool), typeof(PasswordBoxHelper), + new PropertyMetadata(false, OnBindPasswordChanged)); + + public static string GetBoundPassword(DependencyObject dp) + { + return (string)dp.GetValue(BoundPasswordProperty); + } + + public static void SetBoundPassword(DependencyObject dp, string value) + { + dp.SetValue(BoundPasswordProperty, value); + } + + public static bool GetBindPassword(DependencyObject dp) + { + return (bool)dp.GetValue(BindPasswordProperty); + } + + public static void SetBindPassword(DependencyObject dp, bool value) + { + dp.SetValue(BindPasswordProperty, value); + } + + private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is PasswordBox passwordBox) + { + passwordBox.Password = (string)e.NewValue; + } + } + + private static void OnBindPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not PasswordBox passwordBox) + { + return; + } + + if ((bool)e.OldValue) + { + passwordBox.PasswordChanged -= PasswordChanged; + } + + if ((bool)e.NewValue) + { + passwordBox.PasswordChanged += PasswordChanged; + } + } + + private static void PasswordChanged(object sender, RoutedEventArgs e) + { + if (sender is PasswordBox passwordBox) + { + var boundPassword = GetBoundPassword(passwordBox); + if (passwordBox.Password != boundPassword) + { + SetBoundPassword(passwordBox, passwordBox.Password); + } + + } + } + } +} \ No newline at end of file diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml index fde2c10..ce98733 100644 --- a/Views/MainWindow.xaml +++ b/Views/MainWindow.xaml @@ -4,32 +4,38 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:helpers="clr-namespace:VideoConcat.Helpers" xmlns:local="clr-namespace:VideoConcat" mc:Ignorable="d" - Title="登录" Height="300" Width="500" - ResizeMode="NoResize" WindowStartupLocation="CenterScreen" - > + Title="登录" + Height="300" + Width="500" + ResizeMode="NoResize" + WindowStartupLocation="CenterScreen"> - - - + + + - + - + - - + + 用户登录 - + @@ -39,7 +45,8 @@ SelectionBrush="#FFD94448" materialDesign:HintAssist.Hint="输入 用户名"/> - + @@ -49,8 +56,17 @@ CaretBrush="#FFD94448" SelectionBrush="#FFD94448" materialDesign:HintAssist.Hint="输入 密码" - x:Name="Password" - /> + x:Name="Password"/> + + diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index db89f96..9b28704 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -14,7 +14,7 @@ namespace VideoConcat.Views private void BtnExit_Click(object sender, RoutedEventArgs e) { - this.Close(); + Close(); } private void BtnLogin_Click(object sender, RoutedEventArgs e) diff --git a/Views/Video.xaml b/Views/Video.xaml index ed61604..92d02f2 100644 --- a/Views/Video.xaml +++ b/Views/Video.xaml @@ -4,6 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers" xmlns:local="clr-namespace:VideoConcat.Views" mc:Ignorable="d" Title="视频拼接" Height="600" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> @@ -48,7 +49,7 @@ - +