JoeTaicoon
JoeTaicoon

Reputation: 1567

XAML global style with gradient as background

You can set a gradient background inside the xaml for a page like this

<Button.Background>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
        <GradientStop Color="White" Offset="0.6" />
        <GradientStop Color="Blue" Offset="1.0" />
    </LinearGradientBrush>
</Button.Background> 

but when I search for the format to use when doing this in a global style like

<ResourceDictionary>
  <Style TargetType="Button">
    <Setter Property="BorderColor" Value="Lime" />
    <Setter Property="BorderRadius" Value="10" />
    ......

I find nothing usable. It seems that is might not even be doable? Most links even seem to think there is no direct support for gradients without plugins, so perhaps it is a new addition to xamarin forms?

I specifically want to do this for buttons and contentpages, but I suspect the format will be the same for both - if it is supported at all.

Upvotes: 1

Views: 1362

Answers (1)

Cfun
Cfun

Reputation: 9701

You can try with the following:

<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>

Keep in mind that currently Xamarin.forms is having an issue with global implicit style

Documentation: styles-and-templates

Upvotes: 4

Related Questions