我创建了自己的按钮模板,其中有一个画布,其中定义了一些相互重叠的渐变。
基本按钮为灰色
<Style x:Key="ButtonGrey" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Width" Value="200" />
<Setter Property="Height" Value="40" />
<Setter Property="FontSize" Value="24" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontFamily" Value="Utsaah" />
<Setter Property="Foreground" Value="#FFE6E7E8" />
<Setter Property="Margin" Value="0,0,0,2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border"
BorderThickness="2"
Margin="-2"
BorderBrush="{x:Null}" >
<Canvas x:Name="ButtonGreyCanvas">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="InvalidFocused"/>
<VisualState x:Name="InvalidUnfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!-- Button complex background -->
<Path x:Name="Bg1" Data="M0,40L200,40L200,0L0,0z" Stretch="Fill" Fill="{DynamicResource ButtonGreyBg1}" />
<Path x:Name="Bg2" Data="M0,40L200,40L200,0L0,0z" Stretch="Fill" Fill="{DynamicResource ButtonGreyBg2}" />
<!-- middle high dark strip -->
<Path x:Name="Bg3" Data="F1M200,20L0,20L0,40L200,40z" Fill="{DynamicResource ButtonGreyStripBg3}" Opacity="0.30000299215316772" Stretch="Fill" Canvas.Top="20" />
<ContentPresenter
Content="{TemplateBinding Content}"
Margin="40,8,0,0"/>
<ContentPresenter
Content="{TemplateBinding Content}"
TextBlock.Foreground="#1EE6E7E8"
Margin="41.5,6.8,0,0"/>
</Canvas>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter TargetName="Border" Property="BorderThickness" Value="1.3" />
<Setter TargetName="Border" Property="Margin" Value="-1.3" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
</Trigger>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderThickness" Value="2" />
<Setter TargetName="Border" Property="Margin" Value="-2" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
<Setter Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter TargetName="Border" Property="BorderThickness" Value="2" />
<Setter TargetName="Border" Property="Margin" Value="-2" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonGreyOverBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在我只想将 Bg1、Bg2 和 Bg3 路径更改为不同的渐变画笔,所以我创建了继承自 ButtonGrey(称为 ButtonBlue)的新样式,但我无法简单地访问这些路径(Bg1、Bg2 和 Bg3)直接,比如
<Style x:Key="ButtonBlue" TargetType="Button" BasedOn="{StaticResource ButtonGrey}">
<Setter TargetName="Bg1" ...???... />
</Style>
谁能帮助如何访问画布上的这些路径?
非常感谢!