using System.Windows; using System.Windows.Controls; namespace PLCSharp.Core.UserControls { /// /// PasswordBoxNew.xaml 的交互逻辑 /// public partial class PasswordBoxNew : UserControl { /// /// 密码Box新建 /// public PasswordBoxNew() { InitializeComponent(); } private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) { Text = ((PasswordBox)sender).Password; } /// /// Text /// public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc... /// /// TextProperty /// public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(PasswordBoxNew), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, TextSourceChangedCallback)); private static void TextSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { var obj = ((PasswordBoxNew)d); if (obj.Text == "") obj.passwordBox.Password = obj.Text; } } }