1

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>
Dragon Warrior
  • 307
  • 3
  • 16

1 Answers1

1

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> 
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23
  • Ahh, I've found out that I've added `Device.SetFlags` below the `InitializeComponent()` `App.xaml.cs`, this line should be on top. – Dragon Warrior Oct 19 '20 at 08:19