Test
作者:互联网
//MenuItem
<!--子菜单-->
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="Background" Value="#1E1F23"/>
<!--菜单背景色-->
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition />
<ColumnDefinition Width="0" x:Name="arrowWidth"/>
</Grid.ColumnDefinitions>
<!--文本-->
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{TemplateBinding Header}" Foreground="White" Margin="0,3,10,3"/>
<!--箭头-->
<Polyline Grid.Column="2" Points="0,0 5,5 0,10" Stroke="{TemplateBinding Foreground}" VerticalAlignment="Center" Margin="5,0,8,0"/>
<!--子菜单-->
<Popup AllowsTransparency="True" HorizontalOffset="5" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right">
<Border Margin="10" CornerRadius="5" Background="{TemplateBinding Background}">
<Grid>
<Polyline Points="5,0 0,5 5,10" Fill="{TemplateBinding Background}" Margin="-5,10,0,0"/>
<ItemsPresenter />
</Grid>
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Role" Value="SubmenuHeader">
<Setter TargetName="arrowWidth" Property="Width" Value="Auto"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
//TitleMenu
<Style TargetType="{x:Type TitleMenu}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Height" Value="auto"/>
<Setter Property="Background" Value="#fff"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TitleMenu}">
<Grid Background="{TemplateBinding Background}" ClipToBounds="True">
<ItemsPresenter/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
//TitleMenuItem
<!--顶部菜单-->
<Style TargetType="{x:Type TitleMenuItem}">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Background" Value="#1E1F23"/>
<Setter Property="Foreground" Value="#FFF"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TitleMenuItem}">
<Grid>
<Grid VerticalAlignment="Center" WindowChrome.IsHitTestVisibleInChrome="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!--标题-->
<TextBlock Grid.Column="0" Text="{TemplateBinding Header}" Foreground="White" Margin="10,0" VerticalAlignment="Center"/>
</Grid>
<!--弹出面板-->
<Popup Placement="Bottom" AllowsTransparency="True" Width="auto" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" >
<Border Background="{TemplateBinding Background}" Margin="5" CornerRadius="10" VerticalAlignment="Center" >
<Grid>
<!--子项向上的箭头-->
<Polyline HorizontalAlignment="Left" Points="0,5 5,0 10,5" Fill="{TemplateBinding Background}" Margin="10,-4,0,0"/>
<ItemsPresenter />
</Grid>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
标签:Test,MenuItem,TitleMenu,TitleMenuItem 来源: https://www.cnblogs.com/LeiYang5237/p/16515765.html