[英]Allow WPF button navigation via keys with stringformat and _
让我们说我有一个按钮:
<Button Name="BtnOk"
Content="OK"
IsDefault="True">
现在,当我放置_内部的内容时,我可以使用后面带有按键的按钮,例如,我可以直接使用以下按钮(无需聚焦于他),同时按下按键o。
<Button Name="BtnOk"
Content="_OK">
我怎么用绑定做到这一点?
我尝试了以下两种方法:
根本不显示_
:
<Button Name="BtnOk" Content="{Binding SomePath, StringFormat=_{0}">
在字母前面显示下划线,而不是在他下面:
<Button Name="BtnOk" Content="{Binding SomePath" ContentStringFormat="_{0}">
如何在单词的第一个字母下方获得下划线,以便通过该字母的击键完成导航?
该按钮位于我从其他地方使用的用户控件中,按钮的文本被绑定到依赖属性,如下所示:
Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyUserControl}}, Path=SomePath}"
您是否尝试过使用AccessText
:
<Button Name="BtnOk" Content="OK"IsDefault="True">
<AccessText Text={Binding SomePath} />
</Button>
UPDATE
由于您的绑定没有下划线,您可以使用StringFormat
来解决。
<Button Name="BtnOk" IsDefault="True">
<AccessText Text="{Binding SomePath, StringFormat=_{0}}" />
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.