Note that there are some explanatory texts on larger screens.

plurals
  1. POContext Menu trigger not firing on TreeViewItem
    primarykey
    data
    text
    <p>In my WPF application, I have added a TreeView control binding class data to TreeViewItems. I have added a context menu to the treeviewitems. The Handler of the contextMenu is not firing. Here is the XAML code for TreeView.</p> <pre><code>&lt;TreeView ItemsSource="{Binding pads}" Width="190"&gt; &lt;TreeView.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type TreeViewItem}"&gt; &lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&gt; &lt;Setter Property="FontWeight" Value="Normal" /&gt; &lt;Setter Property="ContextMenu"&gt; &lt;Setter.Value&gt; &lt;ContextMenu&gt; &lt;MenuItem Header="Rename" Command="{Binding RenameCommand}"/&gt; &lt;/ContextMenu&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="FontWeight" Value="Bold" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/TreeView.ItemContainerStyle&gt; &lt;TreeView.ItemTemplate&gt; &lt;HierarchicalDataTemplate ItemsSource="{Binding Members}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding Name}" /&gt; &lt;TextBlock Text=" [" Foreground="Blue" /&gt; &lt;TextBlock Text="{Binding Members.Count}" Foreground="Blue" /&gt; &lt;TextBlock Text="]" Foreground="Blue" /&gt; &lt;/StackPanel&gt; &lt;HierarchicalDataTemplate.ItemTemplate&gt; &lt;DataTemplate DataType="{x:Type vm:PadInfo}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="["&gt;&lt;/TextBlock&gt; &lt;TextBlock Text="{Binding SlotID}" /&gt; &lt;TextBlock Text="] ["&gt;&lt;/TextBlock&gt; &lt;TextBlock Text="{Binding WellID}" /&gt; &lt;TextBlock Text="]"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/HierarchicalDataTemplate.ItemTemplate&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.ItemTemplate&gt; &lt;/TreeView&gt; </code></pre> <p>These are the two classes that are binded to the TreeView.</p> <pre><code> /// &lt;summary&gt; /// Class to hold the Pads info for a tree /// &lt;/summary&gt; public class Pad { /// &lt;summary&gt; /// Default Constructor /// &lt;/summary&gt; public Pad() { this.Members = new ObservableCollection&lt;PadInfo&gt;(); } /// &lt;summary&gt; /// Name of the pad /// &lt;/summary&gt; public string Name { get; set; } /// &lt;summary&gt; /// Members of the pad /// &lt;/summary&gt; public ObservableCollection&lt;PadInfo&gt; Members { get; set; } } /// &lt;summary&gt; /// Class to hold the well and slot IDs snapped to a pad /// &lt;/summary&gt; public class PadInfo { /// &lt;summary&gt; /// Slot ID /// &lt;/summary&gt; public string SlotID { get; set; } /// &lt;summary&gt; /// Well ID /// &lt;/summary&gt; public string WellID { get; set; } } </code></pre> <p>}</p> <p>This member is bind to the TreeView</p> <pre><code>public List&lt;Pad&gt; pads { get; set; } </code></pre> <p>When I right click on the menu items, the RenameCommand event is not firing. When I change the to the handler is fired but TreeView is not populated with the binded data.</p> <p>Please help. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload