我开发了一个 DLL 库,该库扩展了 WPF Menu
/MenuItem
类,具有一些功能,包括皮肤。这个库有以下类:
public class MyMenu : Menu {...}
public class MyMenuItem : MenuItem {...}
每个类都有一个静态构造函数来覆盖DefaultStyleKey
soMyMenu
并MyMenuItem
使用 Generic.xaml 中定义的默认样式:
<Style TargetType="{x:Type local:MyMenu}">...
<Style TargetType="{x:Type local:MyMenuItem}">...
一切正常。但我还需要实现一个Separator
应该通过 Generic.xaml 模板化的自定义菜单。所以我有另一堂课:
public class MySeparator : Separator {...}
我尝试使用 MSDN 中描述的方法:http: //msdn.microsoft.com/en-us/library/system.windows.controls.menuitem.separatorstylekey
(VS.85).aspx
这种方式(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>
但它不起作用。在我的目标应用程序中,我使用如下 DLL 库类 (MainWindow.xaml):
<lib:MyMenu>
<lib:MyMenuItem Header="Item 1"/>
<lib:MySeparator/>
<lib:MyMenuItem Header="Item 2"/>
</lib:MyMenu>
所以我的问题是:如何实现Separator
通过 Generic.xaml 风格化的派生菜单?