Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
149502 | Nov 27,2019 10:41 PM UTC | Dec 2,2019 08:33 AM UTC | WPF | 4 |
![]() |
Tags: MenuAdv |
# MainWindow.xaml
<Window.InputBindings>
<KeyBinding Command="{Binding Command}" Key ="{Binding Command.Gesture.Key}" Modifiers="{Binding Command.Gesture.Modifiers}"></KeyBinding>
</Window.InputBindings>
<Grid>
<syncfusion:MenuAdv x:Name="menu" HorizontalAlignment="Left" Height="72" VerticalAlignment="Top" Width="206">
<syncfusion:MenuItemAdv Header="_Edit" >
<syncfusion:MenuItemAdv InputGestureText="{Binding Command.GestureText}" Header="{Binding Command.Text}"/>
</syncfusion:MenuItemAdv>
</syncfusion:MenuAdv>
</Grid>
# MainWindow.xaml.cs
public partial class MainWindow : Window
{
public ICommand Command { get; set; }
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
Command = new CommandWithHotkey("Cut", Key.X, ModifierKeys.Control);
}
}
public class CommandWithHotkey : ICommand
{
public CommandWithHotkey(string text, Key key, ModifierKeys modifier)
{
Text = text;
Gesture = new KeyGesture(key, modifier);
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
MessageBox.Show("MenuItem Clicked : " + Text);
}
public KeyGesture Gesture { get; set; }
public string GestureText
{
get { return Gesture.GetDisplayStringForCulture(CultureInfo.CurrentUICulture); }
}
public string Text { get; set; }
public event EventHandler CanExecuteChanged;
}
|
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.