我正在使用LayoutDocumentPaneGroup
向我的应用添加标签。不幸的是,更改标签后,我无法将焦点设置到标签内容内的某个组件(例如按钮或文本文档)。所以我要实现的是,当更改选项卡时,将选择下面的WPF文件的按钮或文本框。
<xcad:LayoutDocumentPaneGroup >
<xcad:LayoutDocumentPane>
<xcad:LayoutDocument ContentId="document1" Title="Document 1" IconSource="../Images/document.png" >
<Button Content="Document 1 Content" x:Name="myButton" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</xcad:LayoutDocument>
<xcad:LayoutDocument ContentId="document2" Title="Document 2" IconSource="../Images/document.png">
<TextBox Text="Document 2 Content" AcceptsReturn="True"/>
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup >
我已经尝试了很多有关Keyboard.Focus
和`myComponent的事情。
layoutDocument.IsSelectedChanged += LayoutOnIsSelectedChanged;
...
private void LayoutOnIsSelectedChanged(object sender, EventArgs e)
{
myButton.Focus();
Keyboard.Focus(myButton);
}
但是这些方法都没有帮助。更改选项卡后,此示例中的Button从未聚焦。
有什么想法可以设置焦点吗?
----更新2019/03/19(使用FocusManager也不起作用)
<xcad:LayoutDocumentPaneGroup >
<xcad:LayoutDocumentPane>
<xcad:LayoutDocument ContentId="document1" Title="Document 1" FocusManager.FocusedElement="{Binding ElementName=myButton}">
<Button x:Name="myButton" Content="Document 1 Content" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</xcad:LayoutDocument>
<xcad:LayoutDocument ContentId="document2" Title="Document 2" FocusManager.FocusedElement="{Binding ElementName=myTextBox}">
<TextBox x:Name="myTextBox" Text="Document 2 Content" AcceptsReturn="True"/>
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup >