'XAML Theme not getting the Background color property
I have a button that uses my own theme by using style= I want the theme code to pick up and use the Background color property but everything I've tried always fetches black #000000 from the XAML code.
I use it like this:
<Button Background="#844eff" Style="{StaticResource PosButtonTheme}" Content="Return
Sale" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,44,0,0" />
My theme code looks like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style BasedOn="{StaticResource {x:Type Button}}"
TargetType="{x:Type Button}"
x:Key="PosButtonTheme">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel
Margin="0,0,0,0">
<Border Width="62" Height="62">
<Border.Background>
<LinearGradientBrush StartPoint ="0,0" EndPoint ="1,2">
<GradientStop Color= "{TemplateBinding Property=Background}" Offset="0.0"/>
<GradientStop Color= "#FFFFAF" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Border.Clip>
<RectangleGeometry RadiusX="7" RadiusY="10" Rect="0,0,62,62"/>
</Border.Clip>
<Grid>
<StackPanel>
<TextBlock Text= "{TemplateBinding Property=Content}" TextAlignment="Center" Foreground="White" FontSize="14" FontFamily="Barlow Semi Condensed SemiBold" FontWeight="SemiBold" Margin=" 0,15,0,0"/>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
The "{TemplateBinding Property=Content}" works fine in the TextBlock but "{TemplateBinding Property=Background}" seems to do nothing its always black or #000000
Any ideas?
Solution 1:[1]
You code is ok, so I think you miss to set the BackGround property. This is what I tried:
Background = Brushes.Red;
and then
Background = Brushes.Blue;
if this not work for you check this https://stackoverflow.com/a/6748306/3464775
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


