2 HierarchicalDataTemplate을 사용하여 rquired 형식으로 데이터를 표시하는 내 Silverlight 응용 프로그램에 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>
이 컨트롤은 Observable BurstPage 클래스 목록에 바인딩됩니다. 완전한 데이터 구조는 다음과 같습니다.
부모 요소는 1 ~ n 개의 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 : TreeViewItem"> ' –