Skip to content

Instantly share code, notes, and snippets.

@JoanComasFdz
Created January 3, 2012 15:56
Show Gist options
  • Save JoanComasFdz/1555473 to your computer and use it in GitHub Desktop.
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.
<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