c# - 如何在 WPF 的内容控件中为用户控件设置 Taborder?

标签 c# wpf mvvm

我有一个窗口,其中有两个内容控件,我在运行时在其中加载用户控件, 我需要为 ContentControl1 和 ContentControl2 中的用户控件设置 Tab 键顺序吗? 我怎样才能做到这一点?

最佳答案

您可以使用 KeyboardNavigation.TabNavigation 和 KeyboardNavigation.TabIndex 来实现这一点。

示例:

<ContentControl Content="{Binding Head}" x:Name="HeadCtrl" Height="50" ContentTemplate="{StaticResource VectorTemplate}"/>

 <DataTemplate x:Key="VectorTemplate">
    <StackPanel KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.TabIndex="-1">
         <Button Content="{Binding Path=X}" KeyboardNavigation.TabIndex="0" ></Button>
         <Button Content="{Binding Path=Y}" KeyboardNavigation.TabIndex="1" ></Button>
    </StackPanel>
 </DataTemplate>

关于c# - 如何在 WPF 的内容控件中为用户控件设置 Taborder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9510961/

相关文章:

WPF Prism 交互请求触发器 : Re-create View and ViewModel upon show

c# - 在 XAML 中绑定(bind)其 SelectedItem 和 ItemsSource 时设置 ComboBox 的 SelectionChanged 事件

c# - 如何开始使用 MVVM 模型实现串口控制?

c# - 如何让 C# Xamarin.Android 应用程序在手机启动时运行?

c# - Web API 核心 2.2 中的延迟加载

c# - 有没有办法用白色激活一个窗口?

WPF按钮无边框无背景

Xamarin Forms 选择器的默认值

使用 RouteBase 的 C# MVC 路由

c# - 使用带有 bool 值的 C# 维护 ASP.NET 3.5 中的 session 状态