XAML 以渐变为背景的全局样式

XAML global style with gradient as background

您可以在 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 表单的新增功能?

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

您可以尝试以下方法:

<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