This project is read-only.

Keyboard focus

May 20, 2009 at 1:49 PM

Hi, Ado

I have a problem.
I created MyUserControl:

<ad:DockableContent x:Class="AvalonDockTest.MyDockableContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
    xmlns:local="clr-namespace:AvalonDockTest"  
    >
    <ad:DockableContent.CommandBindings>
        <CommandBinding Command="{x:Static local:MyDockableContent.MyCommand}" Executed="CommandBinding_Executed" />
    </ad:DockableContent.CommandBindings>
    <Grid Background="LightCyan">
        <TextBox Margin="40,31,0,0" HorizontalAlignment="Left" Width="145" Height="23" VerticalAlignment="Top" />
        <CheckBox Name="checkBox" Margin="39,87,0,0" HorizontalAlignment="Left" Width="68" Height="16" VerticalAlignment="Top">CheckBox</CheckBox>
        <Button Height="23" Command="{x:Static local:MyDockableContent.MyCommand}" HorizontalAlignment="Left" Margin="39,59,0,0" VerticalAlignment="Top">Button</Button>
    </Grid>
</ad:DockableContent>
+
namespace AvalonDockTest
{
    public partial class MyDockableContent : DockableContent
    {
        static MyDockableContent()
        {
            MyCommand.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Control));
        }

        public MyDockableContent()
        {
            InitializeComponent();
        }

        public static readonly RoutedCommand MyCommand = new RoutedCommand();

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("Command");
        }
    }
}

Then I use it for creating application window:
<Window x:Class="AvalonDockTest.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clr-namespace:AvalonDock;assembly=AvalonDock"
    xmlns:local="clr-namespace:AvalonDockTest"
    Title="Example" Height="600" Width="800" >
    <DockPanel>
        <my:DockingManager>
            <my:ResizingPanel Orientation="Horizontal" >
                <my:DockablePane>
                    <local:MyDockableContent Title="MyContent1"/>
                </my:DockablePane>
                <my:DocumentPane>
                    <local:MyDockableContent Title="MyContent2"/>
                </my:DocumentPane>
            </my:ResizingPanel>
        </my:DockingManager>
    </DockPanel>
</Window>

Now about problem:
1. Run program.
2. Click on header "MyContent1" for setting active content
3. Ctrl+D for executing MyCommand.
Command does not execute.
If I click on TextBox in "MyContent1" and repeat Ctrl+D then command will be executed.
Keyboard focus must be situated within MyContent1. !!!

Thanks!