我在使用MVVM模式标记WPF应用程序上的控件时遇到问题 . 我有以下XAML定义树结构
<Grid Background="Transparent" Margin="10">
<TreeView ItemsSource="{Binding FirstLevelNavigableViewModels}" Background="Transparent"
HorizontalContentAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderThickness="0"
ItemContainerStyle="{StaticResource TreeViewItemStyle1}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type ViewModel:VendorViewModel}" ItemsSource="{Binding Children}">
<View:VendorView HorizontalContentAlignment="Stretch" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type ViewModel:ProductViewModel}">
<View:ProductView HorizontalContentAlignment="Stretch" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
加载树视图时,“ProductView”的XAML如下所示
<Border Margin="0,2,2,2" CornerRadius="3" Background="#3FC7B299" DockPanel.Dock="Right" HorizontalAlignment="Right" Width="109">
<StackPanel Orientation="Vertical" Margin="6,4">
<DockPanel>
<TextBlock DockPanel.Dock="Left" FontFamily="Segoe" FontSize="10" FontWeight="Medium"
Foreground="Black" Opacity="0.75"
Text="CALC. REG. PRICE"></TextBlock>
<Button Width="10" Height="10" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Padding="-4" Margin="0" Command="{Binding UserDefinedRetailPriceCommand}" Visibility="{Binding UserDefinedRetailPriceButtonView}">
<Image Width="10" Height="10" Source="/Arhaus.Pricing.Client;component/Styles/Images/error.png"></Image>
</Button>
</DockPanel>
<TextBox FontFamily="Segoe" FontSize="16" FontWeight="Medium" KeyboardNavigation.IsTabStop="True" KeyboardNavigation.TabIndex="{Binding RegularPriceTabIndex}"
Foreground="Black" Opacity="0.9" KeyboardNavigation.TabNavigation="Continue"
ebf:LostFocusBehaviour.LostFocusCommand = "{Binding LostFocusSugg}"
Text="{Binding NewSuggestedRetailPrice,Converter={StaticResource FormattingConverter}, ConverterParameter=' \{0:C\}', Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Background="#FFE6DED3" BorderBrush="#FFE6DED3" DataContext="{Binding StringFormat=\{0:c\}, NotifyOnValidationError=True}" Padding="0" TabIndex="1"></TextBox>
</StackPanel>
</Border>
我将Tab索引绑定到一个整数,该整数随着树视图的加载而不断增加和绑定(I.E.我将它设置为选项卡索引1,2,3等,因为每个连续的模型都被加载) .
我希望能够点击选项卡并跳转到树视图中的下一个文本框,但是当我单击TAB键时,没有任何反应 . 我不确定我是否正确设置了标签,但我对WPF很新,并且不知道在哪里以及如何设置标签以使其正常工作 . 我已经习惯了WinForms,只需设置选项卡索引并从那里开始 .
感谢您的帮助,我为大型代码块道歉 .
1 回答
我没有准备好解决方案,但有些想法可能有所帮助:
我不知道RegularPriceTabIndex返回什么,但可能它开始于同一索引的每个新TreeViewItem?由于重复使用ProductView,因此多次给出相同的tab-index . 也许这会导致问题 . 您可以尝试为ProductView设置FocusManager.IsFocusScope="true" . 也许这有帮助 .
还可以在TextBox上设置Control.IsTabStop="true" .