关于 CapsLock 的警告
我有一个 DataGridTemplateColumn,其中 DataTemplate 作为密码框。
如果 CapsLock 被切换,我想警告用户。
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (Keyboard.GetKeyStates(Key.CapsLock) == KeyStates.Toggled)
{
...
现在,我需要在这里提出一些 PopUp。 我不知道该怎么做。 请帮帮我。
我尝试像这样使用 ToolTip:
((PasswordBox)sender).SetValue(ToolTipService.InitialShowDelayProperty, 1);
((PasswordBox)sender).ToolTip = "CAPS LOCK";
但只有当鼠标光标悬停在那里并且我需要一个独立的弹出窗口时它才起作用。
I have a DataGridTemplateColumn with DataTemplate as a PasswordBox.
I want to warn user if CapsLock is toggled.
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (Keyboard.GetKeyStates(Key.CapsLock) == KeyStates.Toggled)
{
...
Now, I need to raise some PopUp here. I don't know how to do this. Help me please.
I tried to play around with ToolTip like this:
((PasswordBox)sender).SetValue(ToolTipService.InitialShowDelayProperty, 1);
((PasswordBox)sender).ToolTip = "CAPS LOCK";
But it works only when mouse cursor hovers there and I need an independent Popup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以显示工具提示
You could show a ToolTip
我的解决方案有点不同。 我制作了一个 ContentControl,您可以在其中放置任何内容,它会通知大写锁定状态。 将此类添加到您的代码中。
并向 generic.xaml 添加一些 XAML
您可以对要通知大写锁定的任何内容进行一些控制:
My solution is a little bit different. I made a ContentControl you can put anything inside of, and it will notify the caps lock status. Add this class to your code.
And add some XAML to your generic.xaml
And you can put a little control around anything you want to notify for caps lock:
我制作了警告气球来解决我的 WPF 项目中的 Caps Lock 警告问题。
如果您想在项目中添加此气球警告,请按照以下步骤操作:
- 在您的项目中添加新窗口并命名为“WarningBalloon”。
- 针对新窗口添加以下 XAML 代码,并将警告图标添加到项目的图像文件夹中。
- 在 LoginForm 后面键入以下代码。
I have made warning balloon to solve Caps Lock warning problem in my WPF-Project.
If you want to add this balloon warning in your project then follow these steps:
- Add new Window in your project and give name "WarningBalloon".
- Add following XAML code against new Window and add warning icon to image folder of project.
- Type the following code behind the LoginForm.
它完全取决于您的体系结构,但对于一个简单的解决方案:
您应该设置一个依赖属性,该属性将由窗口上的某种控件观察到,该控件将变得可见并向用户显示警告。
It completely depends on your architecture, but for a simple solution:
You should be setting a Dependency Property, which will be observed by some sort of control on the Window that will become visible and will display the warning for the user.
您好,我研究了约翰的解决方案,并且编写了这个示例:
我使用了相同的类 ShowCapLock。
只是为了制作矢量图像,我使用了 Blend ,对于上框尖点段也是如此。
这是 xaml 代码:
并以这种方式在您想要的任何地方使用它:
Hi I worked on john's solution and I've wrote this example:
I used the same class ShowCapLock.
just to do the vector image I've used the Blend , so also for the upper box cusp segment.
And this is xaml code:
and to use it in your xaml code everywhere you want in this way: