Guest User

Untitled

a guest
Oct 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <ContextMenu x:Key="TreeContextMenuTest" ItemsSource="{Binding ContextMenu}">....
  2.  
  3. <Style TargetType='{x:Type ListViewItem}'>
  4. <Setter Property="ContextMenu" Value="{StaticResource TreeContextMenuTest}" />
  5. </Style>
  6.  
  7. <Setter Property="ContextMenu" Value="{DynamicResource TreeContextMenuTest}" />
  8.  
  9. <Window x:Class="WpfApplication3.MainWindow"
  10. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  11. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  12. Title="MainWindow" Height="350" Width="525">
  13. <Grid>
  14. <Grid.Resources>
  15. <Style TargetType='{x:Type ListViewItem}'>
  16. <Setter Property="ContextMenu" Value="{StaticResource TreeContextMenuTest}" />
  17. </Style>
  18. </Grid.Resources>
  19. <ListView>
  20. <ListViewItem>aaa</ListViewItem>
  21. <ListViewItem>bbb</ListViewItem>
  22. <ListViewItem>ccc</ListViewItem>
  23. </ListView>
  24. </Grid>
  25.  
  26. <Application x:Class="WpfApplication3.App"
  27. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  28. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  29. StartupUri="MainWindow.xaml">
  30. <Application.Resources>
  31. <ContextMenu x:Key="TreeContextMenuTest" ItemsSource="{Binding ContextMenu}"/>
  32.  
  33. </Application.Resources>
  34.  
  35. public partial class App : Application
  36. {
  37. public ObservableCollection<MenuItem> ContextMenu { get; set; }
  38.  
  39. public App()
  40. {
  41. ContextMenu = new ObservableCollection<MenuItem>();
  42. var mi = new MenuItem {Name = "Test"};
  43. ContextMenu.Add(mi);
  44. }
  45. }
Add Comment
Please, Sign In to add comment