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

1.5k Views Asked by At

How can I add LinearGradientBrush as ContentPage.Background in App.xaml's ResourceDictionary? My code pasted below:

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

There are 1 best solutions below

1
On BEST ANSWER

As LinearGradientBrush is a preview concept,don't forgget to add below codes in your App.xaml.cs.

Device.SetFlags(new string[] {"Brush_Experimental" });

and add below to the 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>