我在Silverlight應用程序中有一個treeview控件,它使用2個HierarchicalDataTemplate以顯示格式顯示數據。我希望在第一次打開時自動展開此樹(最好是我可以隨時調用的代碼段)。Silverlight 4:TreeView/HierarchicalDataTemplate/AutoExpand問題
對於給定代碼的任何替代方法也將受到歡迎。
<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)
Thanx Anders,我已經更新了XAML。請現在看看。 –
好吧,我認爲你可以使用我發佈的鏈接中的方法將TreeViewItem的IsExpanded屬性綁定到綁定數據對象中的屬性。 您是否遵循MVVM模式? –
我發現了一個更簡單的自動展開解決方案; ' <樣式的TargetType = 「SDK:樹型視圖」> ' –