This project has moved. For the latest updates, please go here.

PropertyGrid - InputBinding - Key="Enter"

Jan 26, 2012 at 12:45 PM

Hi

I want to press enter in PropertyItem (inside PropertyGrid) was the focus for the next property, how can I do this?

This solution did not work below:

 

                <extToolkit:PropertyGrid.CommandBindings>
                    <CommandBinding Command="NextPage" Executed="EnterKeyPropertyGrid_CmdBinding_Executed"/>
                </extToolkit:PropertyGrid.CommandBindings>
                <extToolkit:PropertyGrid.InputBindings>
                    <KeyBinding Key="Enter" Command="NextPage"/>
                </extToolkit:PropertyGrid.InputBindings>

 

        private void EnterKeyPropertyGrid_CmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            PropertyGrid grid = sender as PropertyGrid;

            if (sender == null)
                return;

            PropertyItem propertyItem = grid.SelectedProperty;

            if (propertyItem == null)
                return;

            for (int i = 0; i < grid.Properties.Count; i++)
            {
                if (grid.Properties[i].BindingPath.Equals(propertyItem.BindingPath))
                {
                    if (i + 1 < grid.Properties.Count)
                    {
                        grid.Properties[i + 1].IsSelected = true;
                        grid.Properties[i + 1].Focus();
                        Keyboard.Focus(grid.Properties[i + 1]);
                        break;
                    }
                }
            }
            
        }

Jan 26, 2012 at 1:40 PM

This is not natively supported in the PropertyGrid.  When I get some time I will investigate your approach to see if I can come up with something to accomplish your task.

Jan 26, 2012 at 7:56 PM
Edited Jan 26, 2012 at 7:57 PM

I solved using this:

            TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
            UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;

            if (keyboardFocus != null)
            {
                keyboardFocus.MoveFocus(tRequest);

                keyboardFocus = Keyboard.FocusedElement as UIElement;

                if (keyboardFocus != null)
                {
                    if (keyboardFocus is System.Windows.Controls.Primitives.ToggleButton)
                    {
                        keyboardFocus.MoveFocus(tRequest);
                    }
                }
            }

Thanks for your time.
Jan 26, 2012 at 7:58 PM

Good job.  I will try to add this to the samples.  It may be useful for someone else trying to accomplish the same task.