【问题标题】:WPF Issue with same ALT hotkey具有相同 ALT 热键的 WPF 问题
【发布时间】:2016-10-24 17:40:08
【问题描述】:

我有一个带有 3 个文本框和标签的窗口,具有以下属性:

 <Label x:Name="label" Content="_Label" Target="{Binding ElementName=textBox}"/>
 <Label x:Name="label1" Content="Label"/>
 <Label x:Name="label2" Content="_Label" Target="{Binding ElementName=textBox2}"/>

See this image

您可以看到“label”和“label2”具有相同的 ALT + L 键,但 Target 属性不同。当我关注 textBox middle 并按下 ALT + L 我需要 textBox2 是焦点(就像在 MFC 中一样) .我不能使用隐藏代码,因为我做了大约 200 个窗口。 非常感谢!

【问题讨论】:

  • 您应该尽可能避免重复的热键...选择另一个字母作为快捷键。如果不可能,请尝试更新其他有冲突的快捷方式。如果仍然不可能,请验证您是否可以更改某些标签(或者可能在末尾的括号中附加一个字母,如 Label1 (_k))。
  • 我还认为,通常情况下,最好让一些控件缺少快捷方式而不是重复一个。它使软件更具可预测性...

标签: c# wpf access-keys


【解决方案1】:

我认为,如果您真的需要不使用 code behindViewModel,您可以通过向 Label1 添加相同的快捷方式来实现,如下所示,

    <Label x:Name="label" Grid.Row="0" Content="_Label" Target="{Binding ElementName=textBox}"/>
    <Label x:Name="label1" Grid.Row="1" Content="_Label" Target="{Binding ElementName=textBox1}"/>
    <Label x:Name="label2" Grid.Row="2" Content="_Label" Target="{Binding ElementName=textBox2}"/>
    <TextBox x:Name="textBox" Grid.Column="1" Grid.Row="0"/>
    <TextBox x:Name="textBox1" Grid.Column="1" Grid.Row="1"/>
    <TextBox x:Name="textBox2" Grid.Column="1" Grid.Row="2"/>

如果您可以制作 ViewModel,那么 InputBindingKeyBinding 可以使其工作。

【讨论】:

    猜你喜欢
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    相关资源
    最近更新 更多