我有一个包含以下内容的标签:Fol_Der
(带有 d 下划线的文件夹,表示 Alt 快捷方式)。
它的目标元素是 Expander。
我的目标是,当用户按 Alt + D 时,扩展器将展开。
但是,按下它时我得到的只是虚线轮廓:
如何正确定位它以使其扩展?
最佳答案
定义命令
public static RoutedUICommand ExpandFolderCommand{ get; private set; }
ExpandFolderCommand= new RoutedUICommand("ExpandFolderCommand", "ExpandFolderCommand", typeof(Commands), new InputGestureCollection {
new KeyGesture(Key.D, ModifierKeys.Alt, "Alt+D") });
然后在窗口/用户控件中定义命令绑定(bind)
<UserControl.CommandBindings>
<CommandBinding Command="{x:Static ExpandFolderCommand}"
Executed="ExpandFolderCommand_Executed"
CanExecute="ExpandFolderCommand_CanExecute"/>
</UserControl.CommandBindings>
ExpandFolderCommand_Executed 应该展开您的扩展器
进一步阅读Commanding Overview
关于c# - 标签目标扩展器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15052160/