1在<Widnow>标签下加入下面标签,意思是Ctrl+Q ,引用的资源是Command ExpnColapSwt 下一步就来添加这个命令资源
<Window.InputBindings>
<KeyBinding Modifiers="Control" Key="Q" Command="{StaticResource ExpnColapSwt}" />
</Window.InputBindings>
2添加一个命令资源
<Window.Resources>
<RoutedUICommand x:Key="ExpnColapSwt" Text="Expaned or Collapse side bar"/>
</Window.Resources>
3.还要定义,当命令发生时,执行的方法动作
private void SomeCommandAction(object sender, RoutedEventArgs e) {
}
4把第二步和第三步的东西绑定到一块来.
<Window.CommandBindings>
<CommandBinding Command="{StaticResource ExpnColapSwt}"
Executed="SomeCommandAction"/>
</Window.CommandBindings>总结'
当按下ctrl+q时,引发了ExpnColapSwt命令
而 ExpnColapSwt和SomeCommandAction绑定到了一起,所以SomeCommandAction将被执行,你现在就可以在
SomeCommandAction里隐藏自己想隐藏或者想显示的控件.这个很简单,你搞的定
<Window.InputBindings>
<KeyBinding Modifiers="Control" Key="Q" Command="{StaticResource ExpnColapSwt}" />
</Window.InputBindings>
2添加一个命令资源
<Window.Resources>
<RoutedUICommand x:Key="ExpnColapSwt" Text="Expaned or Collapse side bar"/>
</Window.Resources>
3.还要定义,当命令发生时,执行的方法动作
private void SomeCommandAction(object sender, RoutedEventArgs e) {
}
4把第二步和第三步的东西绑定到一块来.
<Window.CommandBindings>
<CommandBinding Command="{StaticResource ExpnColapSwt}"
Executed="SomeCommandAction"/>
</Window.CommandBindings>总结'
当按下ctrl+q时,引发了ExpnColapSwt命令
而 ExpnColapSwt和SomeCommandAction绑定到了一起,所以SomeCommandAction将被执行,你现在就可以在
SomeCommandAction里隐藏自己想隐藏或者想显示的控件.这个很简单,你搞的定
强请问知不知道怎么遍历一个窗口里所有控件?谢谢(我刚用window的keryup事件发现也是全局的)
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);