这几天在做一个工具栏,用到了Menu控件,我们都知道它是条目控件,可以绑定数据源。自带的样式不太好看,于是自己就想修改一下,让它默认只有一个子项处于选中状态,再次打开会记录当前选中的是那个MenuItem.思路就是嵌入一个RadioButton控件并让其不可见,控制它的IsChecked属性与MenuItem的IsChecked属性之间的关系,支持添加Icon。
- Xaml及样式
<Window x:Class="WpfApp1Blend.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1Blend"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Window.Resources>
<SolidColorBrush x:Key="Window.ToolBar.Selected.FgColor" Color="#42a4ff"></SolidColorBrush>
<SolidColorBrush x:Key="Window.ToolBar.Selected.BgColor" Color="#0E2E58"></SolidColorBrush>
<SolidColorBrush x:Key="Window.ToolBar.MouseOver.BgColor" Color="#0a2243"></SolidColorBrush>
<SolidColorBrush x:Key="Window.ToolBar.BorderBrushColor" Color="#0d3256"></SolidColorBrush>
<SolidColorBrush x:Key="Window.ToolBar.BgColor" Color="#031527"></SolidColorBrush>
<SolidColorBrush x:Key="Control.Static.FgColor" Color="#A5C0E2"></SolidColorBrush>
<