【发布时间】:2014-11-29 16:49:45
【问题描述】:
ControlTemplate 是否可以使用控件中使用模板的属性?
例如,我有一个按钮,它在 MouseOver 上将颜色更改为红色。但是,我还有一个按钮,看起来完全一样,只是它变成了白色,而不是红色。是否有可能,无论 Button 具有什么 Background 值,然后在控件模板中使用该值?
目前,这是我的 ControlTemplate 的样子:
<ControlTemplate x:Key="CloseButtonTemplate" TargetType="{x:Type Button}">
<Border>
<Border.Style>
<Style>
<Setter Property="Border.Background" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="Border.IsMouseOver" Value="True">
<Setter Property="Border.Background" Value="#FFE53935" />
<Setter Property="Window.Cursor" Value="Hand" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Foreground="#FFEEEEEE" HorizontalAlignment="Center" VerticalAlignment="Center" Text="X" FontFamily="Calibri" />
</Border>
</ControlTemplate>
我想要做的是将Border.Background 设置为Button 背景值。所以如果我有一个<Button Background="Red" />,那么 Border.Background 的值为 Red。
【问题讨论】: