Date : March 29 2020, 07:55 AM
wish helps you If you handle TreeNodeMouseClick, then your TreeNodeMouseClickEventHandler will be passed a TreeNodeMouseClickEventArgs argument. TreeNodeMouseClickEventArgs.Node will be the TreeNode reference you want. See the TreeNodeMouseClick docs for an example similar to: void treeView1_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
TreeNode theTreeNodeIWant = e.Node
}
|
Tag : wpf , By : Puneet Madaan
Date : March 29 2020, 07:55 AM
it should still fix some issue I am trying to disable certain menu items in a treeview's context menu if the SelectedItem property for the treeview is null. My expectation is that this would be most simple to achieve by binding the SelectedItem property of the TreeView to the IsEnabled property of the MenuItem with a converter in between. , here is a workaround using DataTrigger <TreeView Name="treeView">
<TreeViewItem Header="Parent"
IsExpanded="True">
<TreeViewItem Header="Child" />
</TreeViewItem>
<TreeViewItem Header="Sibling" />
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy"
x:Name="copy">
<MenuItem.Style>
<Style TargetType="MenuItem">
<Style.Triggers>
<DataTrigger Binding="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}}"
Value="{x:Null}">
<Setter Property="IsEnabled"
Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem Header="Paste" />
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
|
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Edit - Try this new code. I am using a converter to show and hide the contextmenu based on your property. It works with my sample code. Let me know if you want my sample code. <Grid>
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="VisibilityConverter" />
<ContextMenu x:Key="MenuOne" Visibility="{Binding IsFolder,Converter={StaticResource VisibilityConverter}}">
<MenuItem Header="Add Folder" Command="{Binding AddFolderCommand}"/>
<MenuItem Header="Add Item" Command="{Binding AddItemCommand}"/>
</ContextMenu>
</Grid.Resources>
<TreeView Name="SymbolsTreeView" ItemsSource="{Binding Items}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:MyTreeViewItem}" ItemsSource="{Binding Items}">
<ContentControl>
<TextBlock Text="{Binding Name}"/>
</ContentControl>
</HierarchicalDataTemplate>
<Style TargetType="TreeViewItem">
<Setter Property="ContextMenu" Value="{StaticResource MenuOne}"/>
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.Resources>
</TreeView>
</Grid>
|
Date : March 29 2020, 07:55 AM
|
Tag : javafx , By : Paul McKee
Date : March 29 2020, 07:55 AM
|