I have a ControlTemplate
for my custom button.
Im trying to bind the <Border.Background>
in the ControlTemplate to the Styles Background
property.
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>
How do I make the ControlTemplate
BorderBackground
Property get the value of the Style Background ?
What I have done above is right, is there something Im missing ?
The Background
property on Button
(and on Border
) is of type Brush
but you're attempting to use it as a Color
. Use this instead:
<Border x:Name="Border" Background="{TemplateBinding Background}"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.