Menu
Menu与以往的菜单在基本功能上类似,也像其他WPF控件一样,拥有了WPF的一些新特性,控件嵌套,例如在它的下面可以放一个图片。<Separator/>是菜单中的分割线。
<StackPanel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:media="media"
xmlns:d="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="MenuStyles.Pane1"
Height="221.97"
>
<StackPanel.Resources>
<Style x:Key="Simple" TargetType="{x:Type MenuItem}">
<Setter Property = "Background" Value= "{DynamicResource {x:Static SystemColors.MenuHighlightBrushKey}}"/>
<Setter Property = "Foreground" Value= "{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
<Setter Property = "Height" Value= "{DynamicResource {x:Static SystemParameters.CaptionHeightKey}}"/>
</Style>
<Style x:Key="Triggers" TargetType="{x:Type MenuItem}">
<Style.Triggers>
<Trigger Property="MenuItem.IsMouseOver" Value="true">
<Setter Property = "Foreground" Value="Red"/>
<Setter Property = "FontSize" Value="16"/>
<Setter Property = "FontStyle" Value="Italic"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Menu Width="78" Height="30" Background ="White" d:LayoutOverrides="Height, GridBox">
<MenuItem Header="Triggers Style" Background="LightBlue">
<MenuItem Style="{StaticResource Triggers}" Header="File"/>
<MenuItem Style="{StaticResource Triggers}" Header="New"/>
<Separator/>
<MenuItem Style="{StaticResource Triggers}" Header="Open"/>
<MenuItem Style="{StaticResource Triggers}" Header="Close">
<MenuItem Style="{StaticResource Triggers}" Header="New"/>
<Separator/>
<MenuItem Style="{StaticResource Triggers}" Header="Open"/>
</MenuItem>
<Separator/>
<Image HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="34.333" Height="25.75" Source="data\Sunset.jpg" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</MenuItem>
</Menu>
</StackPanel>
效果如图:
本文参考MSDN组织。
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524