【问题标题】:XAML global style with gradient as background以渐变为背景的 XAML 全局样式
【发布时间】:2021-01-24 19:11:46
【问题描述】:

您可以在 xaml 中为这样的页面设置渐变背景

<Button.Background>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
        <GradientStop Color="White" Offset="0.6" />
        <GradientStop Color="Blue" Offset="1.0" />
    </LinearGradientBrush>
</Button.Background> 

但是当我搜索以全局样式执行此操作时要使用的格式时,例如

<ResourceDictionary>
  <Style TargetType="Button">
    <Setter Property="BorderColor" Value="Lime" />
    <Setter Property="BorderRadius" Value="10" />
    ......

我没有发现任何可用的东西。似乎这甚至可能不可行?大多数链接甚至似乎认为没有插件就没有对渐变的直接支持,所以也许它是 xamarin 表单的新增功能?

我特别想对按钮和内容页面执行此操作,但我怀疑两者的格式相同 - 如果完全受支持的话。

【问题讨论】:

    标签: xaml xamarin.forms styles implicit-style


    【解决方案1】:

    您可以尝试以下方法:

    <ResourceDictionary>
        <Style TargetType="Button">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                        <GradientStop Color="White" Offset="0.6"/>
                        <GradientStop Color="Blue" Offset="1.0"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
    

    请记住,目前 Xamarin.forms 有一个 issue with global implicit style

    文档:styles-and-templates

    【讨论】:

    • 太快了!为此非常感谢。它按预期工作。不过,我想知道为什么我找不到任何有关此的信息。这是一个非常新的功能吗?
    • @JoeTaiconon 不,它是从以前开始的,你没有将你的 Background 属性设置为一个简单的值,而是作为 VisualTree,而不是为什么必须使用这种标记语法。它与渐变无关。
    猜你喜欢
    • 2010-10-05
    • 1970-01-01
    • 2017-11-28
    • 2018-08-09
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多