Created
January 3, 2012 15:56
-
-
Save JoanComasFdz/1555473 to your computer and use it in GitHub Desktop.
Basic TreeView with DataTemplate that contains a ContextMenu capable to bind to TreeView DataContext.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TreeView x:Name="treeExample" | |
ItemsSource="{Binding Items}"> | |
<TreeView.Resources> | |
<DataTemplate DataType="{x:Type yourNamespace:BussinessObjectViewModel}"> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock | |
Name="txtId" | |
Text="{Binding Id}" | |
/> | |
<TextBlock | |
Name="txtSeparator" | |
Text=" - " | |
/> | |
<TextBlock | |
Name="txtName" | |
Text="{Binding Name}" | |
/> | |
<StackPanel.ContextMenu> | |
<ContextMenu> | |
<MenuItem > | |
<MenuItem.Header> | |
<TextBlock Name="txtBindingName" | |
Text="{Binding DataContext.Name, RelativeSource={RelativeSource TemplatedParent}}" | |
/> | |
</MenuItem.Header> | |
</MenuItem> | |
</ContextMenu> | |
</StackPanel.ContextMenu> | |
</StackPanel> | |
</DataTemplate> | |
</TreeView.Resources> | |
</TreeView> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment