Reputation: 301
I develop a DLL library that extends WPF Menu
/MenuItem
classes with some features including skinning. This library has the following classes:
public class MyMenu : Menu {...}
public class MyMenuItem : MenuItem {...}
Each class has a static constructor to override DefaultStyleKey
so MyMenu
and MyMenuItem
use default styles defined in Generic.xaml:
<Style TargetType="{x:Type local:MyMenu}">...
<Style TargetType="{x:Type local:MyMenuItem}">...
Everything works fine. But I also need to realize a custom menu Separator
which should be templated via Generic.xaml. So I have another class:
public class MySeparator : Separator {...}
I tried to use the approach described in MSDN: http://msdn.microsoft.com/en-us/library/system.windows.controls.menuitem.separatorstylekey(VS.85).aspx
This way (Generic.xaml):
<Style x:Key="{x:Static local:MyMenuItem.SeparatorStyleKey}" TargetType="{x:Type local:MySeparator}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MySeparator}">
...
</ControlTemplate>
</Setter.Value>
<Setter/>
</Style>
But it does not work. In my target application I use the DLL library classes as follows (MainWindow.xaml):
<lib:MyMenu>
<lib:MyMenuItem Header="Item 1"/>
<lib:MySeparator/>
<lib:MyMenuItem Header="Item 2"/>
</lib:MyMenu>
So my question is: how to realize a derived menu Separator
stylized via Generic.xaml?
Upvotes: 1
Views: 557
Reputation: 184727
You should not need a new subclass of Separator
, and you can alternatively style the Separators
that appear in your menu by embedding a Style
in the menu's Style
's Resources
.
Upvotes: 2