Reputation: 15367
I am trying to use a context menu and I get the following error as soon as I press the right mouse button:
System.Windows.Style' is not a valid value for property 'ContextMenu'.
XAML code:
<UserControl ...>
<UserControl.Resources>
<ContextMenu x:Key="SharedInstanceContextMenu">
<MenuItem Header="Edit" Command="{Binding Path=EditSelectedItemCommand}"/>
</ContextMenu>
<Style x:Key="MyItemContainerStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="ContextMenu" Value="{StaticResource SharedInstanceContextMenu}" />
</Style>
</UserControl.Resources>
...
<ListView ...
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="ListBoxItem.IsSelected" Value="{Binding Path=IsSelected}" />
<Setter Property="ContextMenu" Value="{StaticResource MyItemContainerStyle}"/>
(I used dots to remove unrelated code).
Does anybody know how to prevent the error (and seeing a context menu)?
Thanks in advance.
Upvotes: 0
Views: 3474
Reputation: 292465
<Setter Property="ContextMenu" Value="{StaticResource MyItemContainerStyle}"/>
MyItemContainerStyle
is a Style
, not a ContextMenu
... you should probably write this instead:
<Setter Property="ContextMenu" Value="{StaticResource SharedInstanceContextMenu}"/>
Upvotes: 3