Silverlightアプリケーションで2つのHierarchicalDataTemplateを使用してrquired形式でデータを表示するtreeviewコントロールがあります。私はこのツリーを最初に開いたときに自動拡張したいと思っています(できればいつでも呼び出すことができるコードスニペットが望ましい)。Silverlight 4:TreeView/HierarchicalDataTemplate/AutoExpand Issue
任意のコードの代替も歓迎します。
<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のキーポイントオブジェクトを持つことがあります。
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:ツリービューアイテム"> ' –