简体   繁体   English

键盘焦点未分配给区域

[英]Keyboard focus not being given to region

I have a project using prism and mvvm light. 我有一个使用棱镜和mvvm光源的项目。 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. 我想做的是将键盘焦点放在画布上,以便可以使用ctrl + click系统选择多行。 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. 当我尝试按Tab键时,左侧区域中的数据网格会更改单元格,这是我所知道的。 Is there a way I can give the canvas keyboard focus while the mouse is in its region? 有没有一种方法可以让鼠标在其区域内时使画布键盘聚焦?

The default value of the Focusable property of a Canvas is false . CanvasFocusable属性的默认值为false You should set this property to true : 您应该将此属性设置为true

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM