Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic Gradients based on App Theming #170

Closed
Orgbrat opened this issue Jun 7, 2021 · 2 comments
Closed

Magic Gradients based on App Theming #170

Orgbrat opened this issue Jun 7, 2021 · 2 comments

Comments

@Orgbrat
Copy link

Orgbrat commented Jun 7, 2021

How would you do Magic Gradients within the XAML on a Xamarin.Forms application that uses AppTheming or different colors for Light and Dark?

@bbenetskyy
Copy link
Collaborator

Hi @Orgbrat here is a link to full source code from example below

Also, here is a link to Demo video on YouTube

Solution №1 - CSS in XAML Binding

ContentPage.Resources>
    <x:String x:Key="LightGradient">
        repeating-linear-gradient(...)
    </x:String>
    <x:String x:Key="DarkGradient">
        repeating-linear-gradient(...)
    </x:String>
</ContentPage.Resources>

<magic:GradientView>
       <magic:CssGradientSource Stylesheet="{x:AppThemeBinding Light={StaticResource LightGradient}, Dark={StaticResource DarkGradient}}"/>
</magic:GradientView>

Solution №2 - CSS in Separate File - Code Behind Binding

.lightGradient {
    background: repeating-linear-gradient(...);
}
.darkGradient{
    background: repeating-linear-gradient(...);
}
//MainPage.xaml.cs
public MainPage()
{
    InitializeComponent();
    
    Application.Current.RequestedThemeChanged += (s, a) =>
    {
        GradientView.StyleClass = new[]
        {
            a.RequestedTheme == OSAppTheme.Light
                ? "lightGradient"
                : "darkGradient"
        };
    };
}

If you don't have any other related questions with App Theming - please close this issue 😉

@Orgbrat Orgbrat closed this as completed Jun 10, 2021
@Orgbrat
Copy link
Author

Orgbrat commented Jun 10, 2021

Thanks, I believe that is just what I needed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants