如何将 LinearGradientBrush 设置为 ContentPages 的背景?

How can I set LinearGradientBrush as the background for of ContentPages?

如何在 App.xamlResourceDictionary 中添加 LinearGradientBrush 作为 ContentPage.Background?我的代码粘贴在下面:

<LinearGradientBrush EndPoint="0,1">
    <GradientStop Color="LightBlue"
                  Offset="0.1" />
    <GradientStop Color="DarkBlue"
                  Offset="1.0" />
</LinearGradientBrush>

由于 LinearGradientBrush 是一个预览概念,请不要忘记在您的 App.xaml.cs.

中添加以下代码
Device.SetFlags(new string[] {"Brush_Experimental" });

并将以下内容添加到 App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <Style  TargetType="ContentPage" ApplyToDerivedTypes="True">
            <Setter Property="Background">
                    <LinearGradientBrush EndPoint="0,1">
                        <GradientStop Color="LightBlue"
              Offset="0.1" />
                        <GradientStop Color="DarkBlue"
              Offset="1.0" />
                    </LinearGradientBrush>
            </Setter>
        </Style>
    </ResourceDictionary>
</Application.Resources>