清除 MenuItem,使用清除命令
你好 我是 wpf 的“非常”初学者 我正在尝试创建一个菜单项“清除”,它应该清除聚焦文本框中的文本, 实际上,我找不到一个内置命令可以完成类似(复制、粘贴、剪切等工作)的工作,
是否有内置命令,或者我是否必须创建一个自定义路由命令,如果是的话 我尝试过但失败了,需要一些想法
我已经制作了 ClearCommandExecuted 逻辑,但问题出在“CanExecute” 我尝试在那里访问 Keyboard.FocusedElement ,但失败了,因为焦点元素是单击时本身的菜单项!!!!
请帮忙 谢谢
hi
i'm a "very" beginner in wpf
i'm trying to make a menu item "Clear", it should clear the text in the focused text box,
actually i could not find a built in command that does the job like (copy,paste,cut..etc)
is there one built in or do i have to make a custom routed command, and if so
i've tried but failed, and need ideas
i've made the ClearCommandExecuted logic, but the problem is with "CanExecute"
i tried to access the Keyboard.FocusedElement there, but failed because the focused element is the menu item it self when it's clicked !!!!
please help
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用传递到 CanExecuteQuery 中的参数之一:
我希望这足以让您朝着正确的方向前进......
You need to use one of the arguments passed into your CanExecuteQuery:
I hope this is enough to get you headed in the right direction...
尝试使用 FocusManager 类。当您的文本框失去键盘焦点时,如果它位于焦点范围内,它仍然具有逻辑焦点。 WPF 中默认为焦点范围的类有 Window、MenuItem、ToolBar 和 ContextMenu。
因此,使用它会给你结果 -
有关更多详细信息,请阅读此 - http:// /msdn.microsoft.com/en-us/library/aa969768.aspx
Try to use the
FocusManager
class. When your TextBox has lost Keyboard Focus, it still has Logical Focus, if it is inside the Focus Scope. Classes in WPF which are focus scopes by default are Window, MenuItem, ToolBar, and ContextMenu.So using this will give you the result -
For more details, read this - http://msdn.microsoft.com/en-us/library/aa969768.aspx