I have a default style for a menu item and context menu styles as follows:
<ResourceDictionary>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White" />
</Style>
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="Background" Value="LightBlue"/>
</Style>
</ResourceDictionary>
When displaying a context menu on a listview item bound to an observable collect I need to override the style as follows:
<ListView.Resources>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="Black" />
</Style>
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="Background" Value="WhiteSmoke"/>
</Style>
<ContextMenu x:Key="ItemContextMenu" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=ContMenu}"/>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource ListItemsStretched}" TargetType="{x:Type ListViewItem}">
<Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}"/>
</Style>
</ListView.ItemContainerStyle>
This works fine until I receive an event I created in the bound ObservableCollection to notify me when any property has changed, this is utilized so I can refresh the ICollectionView which will cause the current sorting of the listview to stay true. However if the context menu is open on the list view when this event occurs, it reverts back to the default style and not the override style.
Any help would be appreciated on this? I suspect it is something simple that I am overlooking.