Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] GradientStop binding color isn't working #11898

Closed
AhmedAbuelnour opened this issue Aug 24, 2020 · 3 comments · Fixed by #11783
Closed

[Bug] GradientStop binding color isn't working #11898

AhmedAbuelnour opened this issue Aug 24, 2020 · 3 comments · Fixed by #11783
Assignees
Labels
a/brushes e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Milestone

Comments

@AhmedAbuelnour
Copy link

Description

Trying to bind a color to GradientStop isn't working as expected

XF Version: 4.8

@AhmedAbuelnour AhmedAbuelnour added s/unverified New report that has yet to be verified t/bug 🐛 labels Aug 24, 2020
@samhouts samhouts added this to New in Triage Aug 24, 2020
@jsuarezruiz jsuarezruiz self-assigned this Aug 24, 2020
@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label Aug 24, 2020
@jsuarezruiz jsuarezruiz moved this from New to Ready For Work in Triage Aug 24, 2020
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Aug 24, 2020
@samhouts samhouts added this to In Progress in vCurrent (4.8.0) Aug 24, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 25, 2020
@samhouts samhouts removed this from In Progress in vCurrent (4.8.0) Aug 26, 2020
@samhouts samhouts added this to In Progress in vNext+1 (5.0.0) Aug 26, 2020
@samhouts samhouts added this to To do in Other Ready For Work Aug 31, 2020
@samhouts samhouts removed this from Ready For Work in Triage Aug 31, 2020
@samhouts samhouts moved this from To do to In progress in Other Ready For Work Aug 31, 2020
@samhouts samhouts moved this from In Progress to Done in vNext+1 (5.0.0) Sep 4, 2020
Other Ready For Work automation moved this from In progress to Done Sep 7, 2020
@samhouts samhouts removed this from Done in Other Ready For Work Nov 3, 2020
@mfeingol
Copy link

mfeingol commented Jan 6, 2021

@rmarinho:

I just tried this out with the XF 5.0 release, using XAML along these lines:

<Grid.Background>
    <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
        <GradientStop Color="{Binding Color, Converter={StaticResource ColorConverter}}" Offset="0" />
        <GradientStop Color="Transparent" Offset="1.5" />
    </LinearGradientBrush>
</Grid.Background>

The Color property is a string, and its value is set during the course of execution. The converter runs and returns the correct result of type Color. But the gradient brush renders fully transparent. If I bind to a property of type Color, it works. Any ideas?

Thanks.

@Aston13
Copy link

Aston13 commented May 12, 2021

The issue seems to lie in finding the binding path.

For anyone encountering this issue, try to explicitly set the path and then bind to that by reference like I have here with 'siteOpType'. My StateColor property is of type Xamarin.Forms.Color.

                <Frame x:DataType="models:BindableSiteOperation" x:Name="siteOpType"
                       BackgroundColor="{Binding StateColor}"
                       Padding="0" 
                       CornerRadius="15">
                    <Grid RowDefinitions="Auto,*"
                          BackgroundColor="{AppThemeBinding Light={StaticResource BackgroundOverlayColorLight}, Dark={StaticResource BackgroundOverlayColorDark}}" 
                          Padding="5">
                        
                        <Grid.ColumnDefinitions HorizontalContentAlignment="Stretch">
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <!--[ Site Icon], [ Site Name ]-->
                        <Grid Grid.ColumnSpan="2" ColumnDefinitions="30,*" Margin="-5">
                            <Grid.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                    <GradientStop Color="{Binding Source={x:Reference siteOpType}, Path=BindingContext.StateColor}" Offset="0.3">
                                    </GradientStop>
                                    <GradientStop Color="Transparent" Offset="1.0"></GradientStop>
                                </LinearGradientBrush>
                            </Grid.Background>

@ipon85new
Copy link

ipon85new commented Aug 16, 2021

I also ran into this bug. The solution was to add the desired color to the dictionary of static resources, and use it through binding

var neededColor = Color.Red; Application.Current.Resources.Add("NeededColor", neededColor );

<StackLayout.Background> <LinearGradientBrush EndPoint="1,0"> <GradientStop Color="{x:StaticResource NeededColor}" Offset="0.1" /> <GradientStop Color="White" Offset="1.0" /> </LinearGradientBrush> </StackLayout.Background>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/brushes e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants