以下xaml工作正常:
<Style x:Key="TopButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Path Data="{StaticResource TopCube}" >
<Path.Style>
<Style>
<Setter Property="Path.Fill" Value="#414042" />
<Style.Triggers>
<Trigger Property="Canvas.IsMouseOver" Value="True">
<Setter Property="Path.Fill" Value="{StaticResource HoveredGradient}" />
</Trigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但当我用Value =“{TemplateBinding Background}”替换Value =“#414042”时,我收到错误'无法识别背景。当我将其更改为Value =“{TemplateBinding Button.Background}”时,它编译得很好,但我在Setter.Value上得到了运行时XAMLparseException
我在这里缺少什么?
答案 0 :(得分:1)
在这种情况下,如果您想获得默认Button.Background
,则需要使用TemplatedParent
绑定
<Setter Property="Path.Fill" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />