Keyboard focus not being given to region

144 views Asked by At

I have a project using prism and mvvm light. I have a shell that defines two regions, Left region and Main Region.

The left region is populated with a user control, it has a data grid with two columns.

The main region is a user control which has an items control inside which is used to display a number of lines on a canvas. It also has a blank data grid which will be used later.

What I am trying to do is have keyboard focus on the canvas so that I can select multiple lines using a ctrl+click system. I have added the following:

 <Canvas x:Name="canvas">
                        <Canvas.Background>
                            <SolidColorBrush Color="White" Opacity="100"/>
                        </Canvas.Background>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="KeyDown">
                                <cmd:EventToCommand Command="{Binding KeyDownCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                            ...
                        </i:Interaction.Triggers>
</canvas>

The issue is that the canvas is not being given keyboard focus. When I attempt to press tab, the data grid in the left region changes cells is how I know this. Is there a way I can give the canvas keyboard focus while the mouse is in its region?

1

There are 1 answers

0
dymanoid On

The default value of the Focusable property of a Canvas is false. You should set this property to true:

<Canvas x:Name="canvas" Focusable="True">
    <!-- your xaml here -->
</Canvas>