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

.NET MAUI style problem with gradient colors - Android #11601

Closed
AbanoubZak opened this issue Nov 24, 2022 · 2 comments · Fixed by #11604
Closed

.NET MAUI style problem with gradient colors - Android #11601

AbanoubZak opened this issue Nov 24, 2022 · 2 comments · Fixed by #11604
Assignees
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing fixed-in-7.0.58 Look for this fix in 7.0.58! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! platform/android 🤖 t/bug Something isn't working

Comments

@AbanoubZak
Copy link

Description

I started using .NET MAUI recently and I found a problem with Styling.
I started with the basic project to make sure the problem is not something I made during the process.
The project starts with a button that will change text and size each time the user press it.
enter image description here

The problem is any time I use LinearGradientBrush directly or through the global styling, the button size doesn't change to fit the text, and even worse it moves to the left.
enter image description here

I looked everywhere but I didn't find any similar problem or solution.

It works well with Windows but not with Android

Code

<Button
                x:Name="CounterBtn"
                Text="Click me"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Center">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#8A26ED"/>
                        <GradientStop Color="#381061" Offset="1"/>
                    </LinearGradientBrush>
                </Button.Background>
            </Button>

Steps to Reproduce

  1. Create new .NET MAUI app
  2. Set LinearGradientBrush to the CounterBtn button directly or use global styling.
  3. When the button click on Android the size doesn't change and the button moves to the left

Link to public reproduction project repository

https://github.com/AbanoubZak/NET-MAUI-gradient-color-styling-problem

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

All Android

Did you find any workaround?

Not yet

Relevant log output

No response

@AbanoubZak AbanoubZak added the t/bug Something isn't working label Nov 24, 2022
@AbanoubZak
Copy link
Author

AbanoubZak commented Nov 24, 2022

Thanks to Liqun Shen-MSFT I figured out that the Button size does change however for some reason the button background doesn't rerender so it looks like it moves to the left but it's just the background color stick to the same area on the left leaving the rest of the button transparent.

I used the workaround but on the SizeChanged event, as it will be more accurate this way since the size of the button depends on the text/content length

 private void CounterBtn_SizeChanged(object sender, EventArgs e)
    {
        LinearGradientBrush ll = new LinearGradientBrush();
        ll.EndPoint = new Point(0, 1);
        GradientStop a = new GradientStop(Color.FromHex("#8A26ED"), 0);
        GradientStop b = new GradientStop(Color.FromHex("#381061"), 1);
        ll.GradientStops = new GradientStopCollection()
    {
        a,b
    };
        CounterBtn.Background = ll;
    }

Original answer

Note: issue still remains and this is just a workaround

@jsuarezruiz jsuarezruiz added platform/android 🤖 area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Nov 24, 2022
@jsuarezruiz jsuarezruiz self-assigned this Nov 24, 2022
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Nov 24, 2022
@ghost
Copy link

ghost commented Nov 24, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jsuarezruiz jsuarezruiz moved this to Todo in MAUI SDK Ongoing Dec 1, 2022
@jsuarezruiz jsuarezruiz moved this from Todo to In Progress in MAUI SDK Ongoing Dec 1, 2022
Repository owner moved this from In Progress to Done in MAUI SDK Ongoing Dec 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2022
@samhouts samhouts added the fixed-in-7.0.58 Look for this fix in 7.0.58! label Feb 16, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 7 + Servicing Feb 16, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! label Feb 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing fixed-in-7.0.58 Look for this fix in 7.0.58! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants