Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ContextMenu x:Key="TreeContextMenuTest" ItemsSource="{Binding ContextMenu}">....
- <Style TargetType='{x:Type ListViewItem}'>
- <Setter Property="ContextMenu" Value="{StaticResource TreeContextMenuTest}" />
- </Style>
- <Setter Property="ContextMenu" Value="{DynamicResource TreeContextMenuTest}" />
- <Window x:Class="WpfApplication3.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
- <Grid.Resources>
- <Style TargetType='{x:Type ListViewItem}'>
- <Setter Property="ContextMenu" Value="{StaticResource TreeContextMenuTest}" />
- </Style>
- </Grid.Resources>
- <ListView>
- <ListViewItem>aaa</ListViewItem>
- <ListViewItem>bbb</ListViewItem>
- <ListViewItem>ccc</ListViewItem>
- </ListView>
- </Grid>
- <Application x:Class="WpfApplication3.App"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- StartupUri="MainWindow.xaml">
- <Application.Resources>
- <ContextMenu x:Key="TreeContextMenuTest" ItemsSource="{Binding ContextMenu}"/>
- </Application.Resources>
- public partial class App : Application
- {
- public ObservableCollection<MenuItem> ContextMenu { get; set; }
- public App()
- {
- ContextMenu = new ObservableCollection<MenuItem>();
- var mi = new MenuItem {Name = "Test"};
- ContextMenu.Add(mi);
- }
- }
Add Comment
Please, Sign In to add comment