我在gradientstop中遇到颜色问题。我希望绑定偏移颜色与我的属性返回颜色(System.Windows.Media),但不工作,并返回defalt颜色透明。如果使用Foreground Label绑定相同的属性是有效的。这种风格在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>
它正在运作:
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="{Binding Path=MyColor,
Converter={StaticResource ColorToBrush}}" />
</Style>
我的财产是:
public Color MyColor
{
set
{
myColor = value;
NotifyPropertyChanged("MyColor");
}
get { return myColor; }
}
谢谢大家的答案