-
Aug 24th, 2010, 02:19 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2010] InputGestureText missing.
Hi guys.
Can anyone tell me what I'm doing wrong here?
When running this, MyMenuItem doesn't have an InputGestureText but the Paste-menu does.
I thought it was supposed to, automatically, find the InputGestureText from the command.
The InputBinding and the Command are working fine. It's just the InputGestureText thats missing...
Code:
<Window x:Class="Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" TextOptions.TextFormattingMode="Display"
UseLayoutRounding="True">
<Window.Resources>
<RoutedUICommand x:Key="MyMenuItemCommand" Text="MyMenuItem" />
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource MyMenuItemCommand}" Executed="MyMenuItemCommand_Executed" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Command="{StaticResource MyMenuItemCommand}" Key="n" Modifiers="Control" />
</Window.InputBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="Menu">
<MenuItem Command="{StaticResource MyMenuItemCommand}" />
<MenuItem Command="Paste" />
</MenuItem>
</Menu>
<Grid>
</Grid>
</DockPanel>
</Window>
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Aug 24th, 2010, 05:09 AM
#2
Re: [2010] InputGestureText missing.
One workaround that I found here is by setting the InputGestureCollection in your code when you are instantiating the RoutedUICommand.
Code:
public partial class MainWindow : Window
{
public static InputGestureCollection gestureCollection = new InputGestureCollection()
{
new KeyGesture(Key.N, ModifierKeys.Control)
};
public static RoutedUICommand MyMenuItemCommand = new RoutedUICommand("MyMenuItem", "MyMenuItemCommand", typeof(Window), gestureCollection);
void MyMenuItemCommand_Executed(object target, ExecutedRoutedEventArgs e)
{
String command, targetobj;
command = ((RoutedCommand)e.Command).Name;
targetobj = ((FrameworkElement)target).Name;
MessageBox.Show("The " + command + " command has been invoked on target object " + targetobj);
}
public MainWindow()
{
InitializeComponent();
}
}
XAML:
Code:
<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" TextOptions.TextFormattingMode="Display"
UseLayoutRounding="True">
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:MainWindow.MyMenuItemCommand}" Executed="MyMenuItemCommand_Executed" />
</Window.CommandBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="Menu">
<MenuItem Command="{x:Static local:MainWindow.MyMenuItemCommand}"/>
<MenuItem Command="Paste" />
</MenuItem>
</Menu>
<Grid>
</Grid>
</DockPanel>
</Window>
-
Aug 24th, 2010, 05:32 AM
#3
Thread Starter
Fanatic Member
Re: [2010] InputGestureText missing.
Thanks.
Strange that one needs to do it through code, though!
But indeed, it does work.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Aug 25th, 2010, 12:56 AM
#4
Re: [RESOLVED] [2010] InputGestureText missing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|