Binding lineargradientbrush color with property

Posted by user1629894 on Stack Overflow See other posts from Stack Overflow or by user1629894
Published on 2012-09-11T08:37:58Z Indexed on 2012/09/30 15:37 UTC
Read the original article Hit count: 190

I have a problem with color in gradientstop. I want binding offset color with my property that return color (System.Windows.Media), but not working and return defalt color Transparent. If binding same property with Foreground Label is working. This style is in ResourceDictionary.

<Style TargetType="{x:Type TabControl}">
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Offset="0.1" Color="Black" />
                    <GradientStop Offset="1" Color="{Binding Path=MyColor}" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

and it's working:

<Style TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="{Binding Path=MyColor, 
            Converter={StaticResource ColorToBrush}}" />
</Style>

my property is:

public Color MyColor
{
    set
    {
       myColor = value;
       NotifyPropertyChanged("MyColor");
    }
    get { return myColor; }
}

Thank you everybody for answers

© Stack Overflow or respective owner

Related posts about c#

Related posts about xaml