protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyCode == Keys.Z && e.Modifiers == (Keys.Shift | Keys.Control))
{
MessageBox.Show("shift + control + z");
}
}
下載頻道介紹三:用戶權限及積分規則詳解 博客頻道8月新增功能介紹 bShare分享,迅速提升10倍流量
WPF 中Menu自定義快捷鍵 .
2011-05-28 10:03 26人閱讀 評論(0) 收藏 舉報
前幾天適用Menu控件,在使用自定義快捷鍵的時候遇到問題,現已解決,代碼如下:
前台:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.CommandBindings>
<CommandBinding Command="local:DataCommands.Requery" Executed="MenuItem_Click" />
</Window.CommandBindings>
<Grid>
<Menu>
<MenuItem Header="Tools">
<MenuItem Header="_快捷鍵" Command="local:DataCommands.Requery" />
</MenuItem>
</Menu>
</Grid>
</Window>
后台:
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Requery");
}
}
public class DataCommands
{
private static RoutedUICommand requery;
static DataCommands()
{
InputGestureCollection inputs = new InputGestureCollection();
inputs.Add(new KeyGesture(Key.G, ModifierKeys.Control, "Ctrl+G"));
requery = new RoutedUICommand(
"Requery", "Requery", typeof(DataCommands), inputs);
}
public static RoutedUICommand Requery
{
get { return requery; }
}
}
}
注意前台引用命名空間
private void OnKeyUp(object sender, KeyEventArgs e)
{
m_key_str = m_key_str + e.Key.ToString();
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。