Results 1 to 4 of 4

Thread: [RESOLVED] [2010] InputGestureText missing.

  1. #1

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Resolved [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...

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    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>
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    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...

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: [RESOLVED] [2010] InputGestureText missing.

    No problem. =)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width