话就不多说,直接给给个例子
比如要修改工具栏ToolBar的Background,
选择ToolBar在属性栏右键点Template将值提取到资源(如下图)
提取到的资源保存,最好保存在资源字典里方便管理.
如提取ToolBar的模板如下
<ControlTemplate x:Key="ToolBarTemplate1" TargetType="ToolBar">
<Grid Margin="3,1,1,1" Name="Grid" SnapsToDevicePixels="True">
<Grid HorizontalAlignment="Right" Name="OverflowGrid">
<ToggleButton ClickMode="Press"
FocusVisualStyle="{x:Null}"
IsChecked="{Binding Path=IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
IsEnabled="{TemplateBinding ToolBar.HasOverflowItems}"
Name="OverflowButton">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="true">
<Setter Property="Control.Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</DataTrigger>
</Style.Triggers>
<!-- 修改的 -->
<Setter Property="Control.Background" Value="#FFD5DCE8">
<!-- 原来的 -->
<!--<Setter Property="Control.Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFEFEEEB" Offset="0" />
<GradientStop Color="#FFE1E1DA" Offset="0.5" />
<GradientStop Color="#FF98987E" Offset="1" />
</LinearGradientBrush>
</Setter.Value>-->
</Setter>
<Setter Property="FrameworkElement.MinHeight" Value="0" />
<Setter Property="FrameworkElement.MinWidth" Value="0" />
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Control.Background}"
CornerRadius="0,3,3,0" Name="Bd" SnapsToDevicePixels="True">
<Canvas Height="7" HorizontalAlignment="Right"
Margin="7,2,2,2" SnapsToDevicePixels="True" VerticalAlignment="Bottom" Width="6">
<Path Data="M1,1.5L6,1.5" Stroke="White" />
<Path Data="M0,0.5L5,0.5" Stroke="{TemplateBinding Control.Foreground}" />
<Path Data="M0.5,4L6.5,4 3.5,7z" Fill="White" />
<Path Data="M-0.5,3L5.5,3 2.5,6z" Fill="{TemplateBinding Control.Foreground}" />
</Canvas>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">