WPF Label Target 访问键

119 阅读1分钟

如图设置Label 的Target属性可以使用Alt+设置字母,快速获取绑定控件的焦点。

<Label VerticalAlignment="Center" Target="{Binding ElementName=firstTxtBox}">_First TextBox:</Label>
<TextBox
    x:Name="firstTxtBox"
    Width="100"
    Height="30" />
<Label VerticalAlignment="Center" Target="{Binding ElementName=secondTxtBox}">_Second TextBox:</Label>
<TextBox
    x:Name="secondTxtBox"
    Width="100"
    Height="30" />
<Label VerticalAlignment="Center" Target="{Binding ElementName=thirdTxtBox}">_Third TextBox:</Label>
<TextBox
    x:Name="thirdTxtBox"
    Width="100"
    Height="30" />

在Label的Content里给想要的访问键字母前加 _

字母前加 下划线 "_"

效果:

按下Alt时:

显示访问键值(字母下有下划线)

按下Alt+F后,焦点聚焦到绑定了的TextBox上: