I have a WPF user control.
In that userControl I’ll have multmple WPF childControls(inherits MyBaseElement).
I need that every ChildControl contains a specified context menu (backward, forward commands)
The code bellow does not work… What I do wrong?
<UserControl.Resources>
<ContextMenu x:Key="ElementContextMenu">
<MenuItem Header="Move backward"
Name="back"
Click="back_Click" />
<MenuItem Header="Move forward"
Name="forw"
Click="forw_Click" />
</ContextMenu>
<Style TargetType="{x:Type my:BaseElement}">
<Setter Property="ContextMenu"
Value="{DynamicResource ResourceKey=ElementContextMenu}" />
A base style isn’t applied automatically to derived elements, you need to create a style for each one. Fortunately you can use style inheritance through the
BasedOnproperty.