我已经创建了自定义控件,并且在该样式中菜单项不起作用我使用 BasedOn 键应用样式
通用 XAML 代码片段
<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中我使用了多个菜单项