<sdk:TreeView x:Name="tvPageManager" SelectedItemChanged="tvPageManager_SelectedItemChanged" 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}" MouseLeftButtonDown="imgPageIcon_MouseLeftButtonDown" 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}" TextChanged="tbPageName_TextChanged" />
</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}" MouseLeftButtonDown="imgMoveUp_MouseLeftButtonDown" Tag="{Binding KeyPointId}"/>
<Image x:Name="imgMoveDn" Source="../Assets/Images/down_arrow.png" Style="{StaticResource MoveIconsStyle}" MouseLeftButtonDown="imgMoveDn_MouseLeftButtonDown" Tag="{Binding KeyPointId}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</sdk:HierarchicalDataTemplate.ItemTemplate>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
对于上面的XAML,我需要以编程方式知道,这是选定的节点还是叶子?
答案 0 :(得分:1)
您已经捕获了选择事件“tvPageManager _ SelectedItemChanged”,因此当前节点作为参数传递(e.NewValue):
private void tvPageManager_SelectionChanged(object sender, RoutedPropertyChangedEventArgs<Object> e)
{
//Perform actions when SelectedItem changes
MessageBox.Show(((TreeViewItem) e.NewValue).Header.ToString());
}
答案 1 :(得分:0)
HiTech Magic, 我很抱歉没有充分解释我的问题,我找到了解决方案;
private void ExpandNodeAndSelectChild()
{
if (branchSelector < 1 || leafSelector < 1)
return;
TreeViewItem item = null;
int itemAtIndex = 0;
//Update tree layout
this.tvName.UpdateLayout();
foreach (var branch in this.tvName.Items)
{
item = (this.tvName.GetContainerFromItem(this.tvName.Items[itemAtIndex]) as TreeViewItem);
if (item != null && item.HasItems)
{
if ((branch as Model.BranchBusinessObject).Id== branchSelector && (!item.IsExpanded))
item.IsExpanded = true;
foreach (var leaf in item.Items)
{
item = (this.tvName.GetContainerFromItem(leaf as Model.LeafBusinessObject) as TreeViewItem);
if (item != null && ((leaf as Model.LeafBusinessObject).Id== leafSelector))
{
item.IsSelected = true;
break;
}
}
}
itemAtIndex++;
}
}