WPF TreeView Command
原创
©著作权归作者所有:来自51CTO博客作者朋克版小红帽的原创作品,请联系作者获取转载授权,否则将追究法律责任
<TreeView ItemContainerStyle="{StaticResource TheStyle}" Background="White" HorizontalAlignment="Stretch" BorderBrush="Transparent" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<prismInt:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Path=SelectedValue}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TreeViewItem ItemsSource="{Binding myobjects}" IsExpanded="True" Focusable="true">
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
<!--<TextBlock Text="{Binding Name}" />-->
<TreeViewItem.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Antennas" DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Add..." Command="{Binding PlacementTarget.DataContext.AddItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</TreeViewItem.HeaderTemplate>
<TreeViewItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete" Command="{Binding Path=DeleteItemCommand}" CommandParameter="{Binding PlacementTarget, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ContextMenu}}}"/>
</ContextMenu>
</TreeViewItem.ContextMenu>
</TreeViewItem>
</TreeView>
-----------------------------------------------------------------------------
ResizeMode="CanMinimize" ShowInTaskbar="True" Topmost="False"