Hi,
I am having an issue with a Style that I am creating. I am making a Style for a Menu and MenuItems. I have two Resource Dictionaries one for my SolidColorBrushes and another for my Styles.
For some reason I can't seem to get any MenuItem's to show using my MenuItem Style. Each time I add the Style tag within a MenuItem tag VS throws an exception at me.
Here is the XAML for my MenuItem Style, it's for a Top Level Menu:
<!--Top Level Menu Items--><Style x:Name="TopLevelMenuItem" TargetType="{x:Type MenuItem}"><!--Menu Item Setters--><Setter Property="FontFamily" Value="Segeo UI Light"/><Setter Property="FontSize" Value="12"/><Setter Property="Foreground" Value="{StaticResource S2ENGINEHD.Text}"/><Setter Property="Padding" Value="2"/><Setter Property="Width" Value="Auto"/><Setter Property="Height" Value="16"/><!--Setting Menu Item Template--><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><!--Menu Item Template--><Border x:Name="MenuItemBorder" BorderThickness="0" Background="{StaticResource S2ENGINEHD.DarkBackground}"><!--Content Resizer--><Viewbox><!--Content Placement--><ContentPresenter x:Name="MenuItemPresenter" HorizontalAlignment="Left" VerticalAlignment="Center" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="{TemplateBinding HeaderStringFormat}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ToolTip="{TemplateBinding ToolTip}"/></Viewbox></Border><ControlTemplate.Triggers><!--On MouseOver Condition--><Trigger Property="IsMouseOver" Value="True"><!--Set Button Background On MouseOver--><Setter Property="Background" TargetName="MenuItemBorder" Value="{StaticResource S2ENGINEHD.Hover}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
Here is it's usage. This is within my MainWindow.xaml:
<!--Top Level Menu--><Grid x:Name="TopLevelMenu" Width="Auto" Height="16" VerticalAlignment="Bottom" Background="{StaticResource S2ENGINE.GradientBackground}" Grid.Row="2"><!--Menu--><Menu Style="{StaticResource TopLevelMenu}"><!--Menu Items--><MenuItem Style="{StaticResource TopLevelMenuItem}" Header="File"/><MenuItem Style="{StaticResource TopLevelMenuItem}" Header="Edit"/><MenuItem Style="{StaticResource TopLevelMenuItem}"Header="Tools"/><MenuItem Style="{StaticResource TopLevelMenuItem}"Header="Game"/><MenuItem Style="{StaticResource TopLevelMenuItem}"Header="Render"/><MenuItem Style="{StaticResource TopLevelMenuItem}"Header="Help"/></Menu></Grid>
Here is a screenshot showing the results:
Here is a screenshot showing the issue I get when I run my application:
I'm not to sure where I have gone wrong. The Style for the MenuItem has a ContentPresenter in the ControlTemplate. The squiggly under the Style declarations is telling me that 'The resource "TopLevelMenuItem" could not be resolved.' Any help is appreciated this one is really confusing me haha.