【问题标题】:XAML Theme not getting the Background color propertyXAML 主题没有获得背景颜色属性
【发布时间】:2022-02-25 23:08:57
【问题描述】:

我有一个通过 style= 使用我自己的主题的按钮

我是这样使用的:

<Button Background="#844eff" Style="{StaticResource PosButtonTheme}" Content="Return
Sale" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,44,0,0" />

我的主题代码如下所示:

<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>

“{TemplateBinding Property=Content}”在 TextBlock 中工作正常,但“{TemplateBinding Property=Background}”似乎什么也没做,它总是黑色或 #000000

有什么想法吗?

【问题讨论】:

  • 在哪里定义 BackGround 属性?

标签: xaml styles themes


【解决方案1】:

您的代码没问题,所以我认为您错过了设置 BackGround 属性。 这是我尝试过的:

Background = Brushes.Red;

然后

Background = Brushes.Blue;

如果这对您不起作用,请检查此https://stackoverflow.com/a/6748306/3464775

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2021-08-28
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多