我有一个多级TreeView,最多有4个级别,如下所示:
data.forEach(fillSales);
这里我在 TreeView.ItemContainerStyle 中有一个setter, Setter Property =“IsExpanded”Value =“{Binding IsExpanded}”但是当我设置TestStamentList为4级时从代码中将IsExpanded属性设置为True,然后该项目不会扩展。我想在Button Click(Find Next Button)事件中扩展具有某些特定条件的子项。
注意: - 我在所有列表级别(4个级别)都有IsExpanded属性,我设置的是上一级列表的IsExpanded = true(TestModuleStatementList)。
下面是我的按钮点击事件:
<HierarchicalDataTemplate ItemsSource="{Binding TestModuleStatementList}" x:Key="level4" ItemTemplate="{StaticResource level5}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="600"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="1,1,0,1" Name="lblStatementName" Style="{StaticResource TreeLabelStyle}" MouseLeftButtonUp="ViewTestDataTree_MouseLeftButtonUp" MouseRightButtonUp="ViewTestDataTree_MouseRightButtonUp" Padding="2,2,2,2" Text="{Binding DisplayText}" />
<Border Grid.Column="1" Margin="0,0,-2,0" Style="{StaticResource BorderStylePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockPassCountStyleTestData}"/>
</Border>
<Border Grid.Column="2" Margin="0,0,-2,0" Style="{StaticResource BorderStyleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockFailCountStyleTestData}"/>
</Border>
<Border Grid.Column="3" Margin="0,0,-2,0" Style="{StaticResource BorderStyleModulePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockModulePassCountStyleTestData}"/>
</Border>
<Border Grid.Column="4" Margin="0,0,-2,0" Style="{StaticResource BorderStyleModuleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockModuleFailCountStyleTestData}"/>
</Border>
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding TestModules}" x:Key="level3" ItemTemplate="{StaticResource level4}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="620"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="1,1,0,1" Name="lblCategoryName" Style="{StaticResource TreeLabelStyle}" MouseLeftButtonUp="ViewTestDataTree_MouseLeftButtonUp" MouseRightButtonUp="ViewTestDataTree_MouseRightButtonUp" Padding="2,2,2,2" Text="{Binding DisplayText}" />
<Border Grid.Column="1" Margin="0,0,-2,0" Style="{StaticResource BorderStylePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockPassCountStyleTestData}"/>
</Border>
<Border Grid.Column="2" Margin="0,0,-2,0" Style="{StaticResource BorderStyleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockFailCountStyleTestData}"/>
</Border>
<Border Grid.Column="3" Margin="0,0,-2,0" Style="{StaticResource BorderStyleModulePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockModulePassCountStyleTestData}"/>
</Border>
<Border Grid.Column="4" Margin="0,0,-2,0" Style="{StaticResource BorderStyleModuleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockModuleFailCountStyleTestData}"/>
</Border>
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding TestModuleCategories}" x:Key="level2" ItemTemplate="{StaticResource level3}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="640"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="1,1,1,1" Name="lblDeviceName" MouseLeftButtonUp="ViewTestDataTree_MouseLeftButtonUp" MouseRightButtonUp="ViewTestDataTree_MouseRightButtonUp" ToolTip="{Binding DisplayText}" Style="{StaticResource TreeLabelStyle}" Padding="2,2,2,2" Text="{Binding DisplayText}" />
<TextBox Grid.Column="0" Margin="1,1,1,1" Name="DeviceNameTextBox" LostFocus="TextBox_LostFocus"
Text="{Binding RenameDeviceText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PreviewKeyDown="TextBox_PreviewKeyDown"
Padding="2,2,2,2" MaxLength="100"
Visibility="{Binding Path=Edit, Converter={StaticResource BoolToVisibilityCollapsedConverter}, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
<TextBox.CommandBindings>
<CommandBinding Command="Paste" CanExecute="CommandBinding_CanExecute"/>
</TextBox.CommandBindings>
</TextBox>
<Border Grid.Column="1" Margin="0,0,-1,0" Style="{StaticResource BorderStylePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockPassCountStyleTestData}"/>
</Border>
<Border Grid.Column="2" Margin="0,0,-1,0" Style="{StaticResource BorderStyleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockFailCountStyleTestData}"/>
</Border>
<Border Grid.Column="3" Margin="0,0,-1,0" Style="{StaticResource BorderStyleModulePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockModulePassCountStyleTestData}"/>
</Border>
<Border Grid.Column="4" Margin="0,0,-1,0" Style="{StaticResource BorderStyleModuleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockModuleFailCountStyleTestData}"/>
</Border>
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding TestRuns}" x:Key="level1" ItemTemplate="{StaticResource level2}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="660"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="1,1,2,1" Name="lblProjectName" MouseLeftButtonUp="ViewTestDataTree_MouseLeftButtonUp" MouseRightButtonUp="ViewTestDataTree_MouseRightButtonUp" Style="{StaticResource TreeLabelStyle}" Padding="2,2,2,2" Text="{Binding DisplayText}"/>
<Border Grid.Column="1" Style="{StaticResource BorderStylePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockPassCountStyleTestData}"/>
</Border>
<Border Grid.Column="2" Style="{StaticResource BorderStyleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockFailCountStyleTestData}"/>
</Border>
<Border Grid.Column="3" Style="{StaticResource BorderStyleModulePassCountTestData}">
<TextBlock Style="{StaticResource TextBlockModulePassCountStyleTestData}"/>
</Border>
<Border Grid.Column="4" Style="{StaticResource BorderStyleModuleFailCountTestData}">
<TextBlock Style="{StaticResource TextBlockModuleFailCountStyleTestData}"/>
</Border>
</Grid>
</HierarchicalDataTemplate>
<TreeView BorderThickness="0" Name="ViewTestDataTree" VirtualizingStackPanel.IsVirtualizing = "True"
VirtualizingStackPanel.VirtualizationMode = "Recycling" ItemsSource="{Binding Projects}" Grid.Row="1"
ItemTemplate="{StaticResource level1}" Background="{StaticResource ATAM_WindowBackground}" FocusVisualStyle="{x:Null}">
<TreeView.ItemContainerStyle>
<!-- Make the focus highlight rectangle, around the current tree item, barely visible -->
<Style TargetType="{x:Type TreeViewItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF202020" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#FF202020" />
</Style.Resources>
<Setter Property="IsExpanded" Value="{Binding IsExpanded}"/>
<EventSetter Event="TreeViewItem.Expanded" Handler="TreeViewItem_Expanded"/>
<EventSetter Event="TreeViewItem.Collapsed" Handler="TreeViewItem_Collapsed"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
请提供一些帮助
提前致谢。
答案 0 :(得分:0)