wpf - How to get MenuItem clicked events from TreeView ContextMenu -
I am inserting TreeViewItems into a TreeView control and setting the style for each one at the time of entry. I am specifying different styles (predefined in XAM), I want to insert the type of trivium (trivium). Some styles include a context menu
My problem is that I am unable to use Click = "MyHandler" on MenuItems; I get an error "Root element requires x: class attribute to support event handlers in XAML file." And apparently there is no root element in the elements within the style block.
Any suggestion was very appreciated.
XAML:
& lt; Style x: key = "area" target type = "{x: type tree viii}}" & gt; & Lt; Setter Property = "Header Template" & gt; & Lt; Setter.Value & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Canvas background = "{DynamicResource Terrain_icon}" /> & Lt; Text block text = "{binding}" /> & Lt; StackPanel.ContextMenu & gt; & Lt; ContextMenu & gt; & Lt; MenuItem Header = "Edit ..." click = "MyHandler" /> & Lt ;! - Error - & gt; & Lt; MenuItem Header = "Add ..." /> & Lt; MenuItem Header = "Delete" /> & Lt; / ContextMenu & gt; & Lt; /StackPanel.ContextMenu> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;
C #:
Enter Private Zero InsertTerrainNode (Object Sender, System.Windows.RoutedEventArgs E) {// New Item under First-Level TreeViewItem Add TreeViewItem tvi = myTree.ItemContainerGenerator.ContainerFromItem (myTree.Items [0]) as TreeViewItem; Treviiitim neutrennode = new tree viiitum (); NewTerrainNode.Header = "Terrain"; NewTerrainNode.Style = (style) this.FindResource ("Terrain"); Tvi.Items.Instert (0, newTerrainNode); }
Use the command, create a category derived from ICommand, declared in that category Use the rules of the user and its command is accessible in your xaml and bound buttons with view
Comments
Post a Comment