何在没有MVVM的WPF中实现按钮中文本的快捷方式 [英] Ho to implement shortcut for text in button in WPF without MVVM

查看:68
本文介绍了何在没有MVVM的WPF中实现按钮中文本的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





有人可以告诉我如何实现按钮的快捷方式。



例如我有一个按钮机智文本保存,我应该在保存时给出快捷方式。

如果我按下Alt v应该突出显示当我点击alt + v时应该执行保存功能。



i googled并获得了使用AcessText的解决方案



代码如下:



Hi,

could anybody please tell me how to implement shortcut for my button.

for example i have one button wit text "Save" and i should give shortcut as v in save.
if i press Alt v should be highlighted and when i click alt+v the save functionality should be executed.

i googled and got a solution as to use "AcessText"

code is like:

<button id="Save">

<accesstext>Sa_ve</accesstext>

</button>





但问题是直接在保存按钮中加下划线一次表格已加载。 v只有在我按下alt键时才会突出显示。



请建议



but the problem is v getting underlined directly in the save button once the form got loaded. v should be highlighted only when i pressed alt key is pressed.

please suggest

推荐答案





这是默认行为。这是操作系统定义的行为。如果你想改变它,你可以在stackoverflow中查看同一篇文章: http://stackoverflow.com/questions/8588004/how-to-show-accesskey-without-pressing-alt-in-wpf [ ^ ]。



您可以在窗口上尝试使用PreviewKeyPress进行某种变通办法,但这真的很尴尬...

或者您可以尝试使用命令,但这样您就可以实现MVVM模式。



LG
Hi,

It's the default behaviour. It's an OS defined behaviour. If you want to change it you may look at this same post in stackoverflow: http://stackoverflow.com/questions/8588004/how-to-show-accesskey-without-pressing-alt-in-wpf[^].

You can try some sort of workarounds with PreviewKeyPress on the window, but it's really awkward...
Or you can try to use Commands, but this way you're going to implement the MVVM pattern.

LG


这篇关于何在没有MVVM的WPF中实现按钮中文本的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆