Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有自定义验证的自定义 TextBlock,但我还需要使用密码框功能。如何制作自定义数字密码框?
只需将 PasswordBox 添加到您的 XAML 中,如下所示:
<PasswordBox x:Name="MyPasswordBox" KeyDown="MyPasswordBox_KeyDown" />
然后使用 KeyDown 事件删除所有不是从 0 到 9 的按键,如下所示:
private void MyPasswordBox_KeyDown(object sender, KeyEventArgs e) { e.Handled = (e.Key < Key.D0 || e.Key > Key.D9); }