![](/img/trans.png)
[英]How to bind ColorBrush from inside ControlTemplate to a custom property outside of ControlTemplate?
[英]Bind a ControlTemplate value to a styles property
我的自定義按鈕有一個ControlTemplate
。
我試圖將ControlTemplate中的<Border.Background>
綁定到Styles Background
屬性。
XAML
<ControlTemplate x:Key="NumberButtonControlTemplate" TargetType="Button" >
<Border x:Name="Border">
<Border.Background>
<SolidColorBrush Color="{TemplateBinding Background}" />
</Border.Background>
</Border>
</ControlTemplate>
<Style x:Key="NumberButtonStyle" TargetType="Button">
<Setter Property="Template" Value="{StaticResource NumberButtonControlTemplate}" />
<Setter Property="Background" Value="MediumSpringGreen" />
<Setter Property="Height" Value="80" />
</Style>
如何使ControlTemplate
BorderBackground
屬性獲得樣式背景的值?
我上面所做的是正確的,我缺少什么嗎?
Button
(和Border
)上的Background
屬性的類型為Brush
但是您嘗試將其用作Color
。 使用此代替:
<Border x:Name="Border" Background="{TemplateBinding Background}"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.