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 answers

1
Leo Zhu 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>