How do I wrap the following XAML in a style?

EasyGoingPatEasyGoingPat GBMember ✭✭✭

I am using the XFGloss nuget package found here: https://github.com/tbaggett/xfgloss

This page shows how to set a background gradient using the following XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xfg="clr-namespace:XFGloss;assembly=XFGloss"
             x:Class="XFGlossSample.Views.AboutPage"
             Title="XFGloss Sample App" Padding="10">

    <xfg:ContentPageGloss.BackgroundGradient>
        <xfg:Gradient Rotation="150">
            <xfg:GradientStep StepColor="White" StepPercentage="0" />
            <xfg:GradientStep StepColor="White" StepPercentage=".5" />
            <xfg:GradientStep StepColor="#ccd9ff" StepPercentage="1" />
        </xfg:Gradient>
    </xfg:ContentPageGloss.BackgroundGradient>
    ...
</ContentPage>

I'd like to wrap this XAML up so that I can easily apply it to multiple screens but my (lack of) XAML skills are letting me down. Can anyone please show me how I would go about doing this?

Kind wishes - Patrick

Tagged:

Best Answer

  • NMackayNMackay GB mod
    Accepted Answer

    Could you not just have a base page which does XFGloss and your other pages just inherit from that page?

Answers

  • NMackayNMackay GBInsider, University mod
    Accepted Answer

    Could you not just have a base page which does XFGloss and your other pages just inherit from that page?

  • PilliPilli USMember ✭✭

    This documentation provides you defining a style and you can use any where in the APP.
    (Make sure define the style in App.Xaml : If you wanted to use it more than one xaml file.)

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/inheritance

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @NMackay said:
    Could you not just have a base page which does XFGloss and your other pages just inherit from that page?

    Yes, I do this already. I was trying to stick with XAML, though. Having said that, I seem to find myself working so hard at XAML in Xamarin that I am considering changing all my pages so that they are simply built in code, perhaps using a handly set of extensions that I found as a nuget package, that make the code-behind C# look a lot like XAML.

    (Can't find the link to that right now. Does it ring any bells with anyone?

    • Patrick
  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @Pilli said:
    This documentation provides you defining a style and you can use any where in the APP.
    (Make sure define the style in App.Xaml : If you wanted to use it more than one xaml file.)

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/inheritance

    Thank you for the link. I've read this. Guess I am being a bit thick, but I still can't work out the syntax to add gradient stops to the gradient.

  • NMackayNMackay GBInsider, University mod

    You can define your base page as Xaml and your other page can inherit from that.

    I'm aware of the library, can't remember the name. You can only do so much in Xamarin Forms xaml, nothing wrong with mixing code UI and XAML.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
Sign In or Register to comment.