我的 silverlight 应用程序中有一个树视图控件,它使用 2 个 HierarchicalDataTemplate(s) 以所需格式显示数据。我希望在第一次打开时自动扩展这棵树(最好是我可以随时调用的代码片段)。
给定代码的任何替代方案也将受到欢迎。
<sdk:TreeView x:Name="tvPageManager" Style="{StaticResource PageManagerStyle}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding KeyPoints, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<ToolTipService.ToolTip>
<ToolTip Content="{Binding PageName}" Style="{StaticResource ToolTipStyle}"/>
</ToolTipService.ToolTip>
<Image x:Name="imgPageIcon" Source="{Binding PageIconImage}" Style="{StaticResource PageIconStyle}" Tag="{Binding BurstPageId, Mode=TwoWay}" />
<TextBlock x:Name="tbkLiteralTextPage" Text="Page " Style="{StaticResource PageNameLiteralTextBlockStyle}" />
<TextBox x:Name="tbPageName" Text="{Binding PageName, Mode=TwoWay}" Style="{StaticResource PageNameTextBoxStyle}" />
</StackPanel>
<sdk:HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="imgKeypointIcon" Source="../Assets/Images/bullet_yellow.png" Style="{StaticResource KeypointIconStyle}"/>
<TextBlock x:Name="tbkKeypointTitle" Text="{Binding Title, Mode=TwoWay}" Style="{StaticResource KeypointNameTextBlockStyle}" />
<StackPanel x:Name="spnlMoveImages" Orientation="Horizontal" HorizontalAlignment="Right" Width="30">
<Image x:Name="imgMoveUp" Source="../Assets/Images/up_arrow.png" Style="{StaticResource MoveIconsStyle}" Tag="{Binding KeyPointId}"/>
<Image x:Name="imgMoveDn" Source="../Assets/Images/down_arrow.png" Style="{StaticResource MoveIconsStyle}" Tag="{Binding KeyPointId}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</sdk:HierarchicalDataTemplate.ItemTemplate>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
此控件绑定到 BurstPage 类的 Observable 列表。完整的数据结构如下:
父元素是包含 1 到 n 个 BurstPage 对象的 Burst 对象,任何给定的 BurstPage 都可能有 1 到 n 个 Keypoint 对象。
BurstPage.Name(比如 1) Keypoint.Name(比如 A) Keypoint.Name(比如 B) Keypoint.Name(比如 C) BurstPage.Name(比如 2) BurstPage.Name(比如 3) Keypoint.Name(比如 D) Keypoint .Name(比如 E)