【发布时间】:2014-09-21 07:31:31
【问题描述】:
我已经创建了自定义控件,并且在该样式中菜单项不起作用我使用了 BasedOn 键来应用样式
通用 XAML 代码 sn-p
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication3">
<Style x:Key="MenuItemStyle" TargetType="{x:Type MenuItem}">
<Setter Property="Height" Value="60"/>
<Setter Property="Background" Value="Red"/>
</Style>
<Style BasedOn="{StaticResource ResourceKey=MenuItemStyle}" TargetType="{x:Type MenuItem}"/>
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Grid x:Name="MainGrid">
<Menu>
<MenuItem Header="File" />
</Menu>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
样式不适用于MenuItem,而添加如下代码的样式正在工作,如何使用基于实现这一点,因为在我的scnorio中我使用了多个菜单项
【问题讨论】: