I can`t seem to get this right click popup menu to work.
<TreeView Name="NavigationPanel" ItemsSource="{Binding NavigationList}" />
<Style TargetType="{x:Type TreeViewItem}" >
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}, Path=DataContext}">
<MenuItem Header="Delete" Command="{Binding Path=CommandPopupClick}" CommandParameter="{Binding Path=SelectedItem}"/>
<Separator />
<MenuItem Header="Properties" Command="{Binding Path=CommandPopupClick}" CommandParameter="{Binding Path=SelectedItem}"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
//Delegated command
public DelegateCommand CommandPopupClick { get; set; }
//Assigning the delegate command.
CommandPopupClick = new DelegateCommand(PopupClick, CanMyCommand);
//Event for rightclick option clicked
public void PopupClick(Object Parameters)
{
var something = Parameters; //Break is here to see if the event fires
}
I can see the popup menu with the items 'Delete' and 'Properties' in it. However, when I click either one of them it doesn't fire the event.
NOTE: the delegate command system works for everything else, I don't think that's the issue.
I really do not want to use Name.Click += new RoutedEvent()
if I can help it.
Thanks.
Errors in Debug as requested
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
'Enterprise.exe' (CLR v4.0.30319: Enterprise.exe): Loaded 'Microsoft.GeneratedCode'.
'Enterprise.exe' (CLR v4.0.30319: Enterprise.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemCore\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemCore.dll'. Cannot find or open the PDB file.
A first chance exception of type 'System.IO.IOException' occurred in PresentationFramework.dll
A first chance exception of type 'System.IO.IOException' occurred in PresentationCore.dll
'Enterprise.exe' (CLR v4.0.30319: Enterprise.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Cannot find or open the PDB file.
The thread 0x1954 has exited with code 259 (0x103).
Resolution:
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu DataContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Delete"
Command="{Binding CommandPopupClick}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}" />
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
<TreeView Name="NavigationPanel" ItemsSource="{Binding NavigationList}" Tag="{Binding Path=DataContext, ElementName=Main}"/>
Thank you for all who assisted.