标签目标扩展器

时间:2013-02-24 13:26:12

标签: c# wpf

我有一个包含此内容的标签:Fol_Der(带有带有下划线的Alt快捷方式的文件夹)。

它所针对的元素是Expander。

我的目标是当用户按下 Alt + D 时,扩展器将会扩展。

然而,按下它时我得到的只是一个虚线轮廓:

Dashed expander

如何正确定位它以便扩展?

1 个答案:

答案 0 :(得分:2)

定义命令

public static RoutedUICommand ExpandFolderCommand{ get; private set; }

 ExpandFolderCommand= new RoutedUICommand("ExpandFolderCommand", "ExpandFolderCommand", typeof(Commands),       new InputGestureCollection { 
                    new KeyGesture(Key.D, ModifierKeys.Alt, "Alt+D") });

然后在Window / UserControl中定义命令绑定

 <UserControl.CommandBindings>
          <CommandBinding Command="{x:Static ExpandFolderCommand}"
                          Executed="ExpandFolderCommand_Executed" 
                          CanExecute="ExpandFolderCommand_CanExecute"/>
 </UserControl.CommandBindings>

ExpandFolderCommand_Executed应该扩展你的扩展器

进一步阅读Commanding Overview

相关问题