C# 笔刷依赖项属性的Silverlight TargetNullValue绑定
我有一个可重用的用户控件,它具有一个设置矩形颜色的依赖属性。该属性使用笔刷作为类型 数据绑定工作正常,但是当绑定有错误或未指定其值时,我希望添加一个回退和null值。 这是我的XAML:C# 笔刷依赖项属性的Silverlight TargetNullValue绑定,c#,xaml,data-binding,silverlight-4.0,C#,Xaml,Data Binding,Silverlight 4.0,我有一个可重用的用户控件,它具有一个设置矩形颜色的依赖属性。该属性使用笔刷作为类型 数据绑定工作正常,但是当绑定有错误或未指定其值时,我希望添加一个回退和null值。 这是我的XAML: <Rectangle Fill="{Binding Path=UnderLineColor, ElementName=Header, FallbackValue=LightGrey, TargetNullValue=LightGrey}
<Rectangle Fill="{Binding Path=UnderLineColor, ElementName=Header,
FallbackValue=LightGrey, TargetNullValue=LightGrey}"
Height="2"
Margin="0,2"
Grid.Row="1"
Grid.ColumnSpan="2" />
问题是SL似乎不接受我指定的回退和空值
我应该在这些属性中写入什么值才能使其工作?或者我应该使用ValueConverter而不是这种方法
编辑:
今天最重要的提示:灰色!=格雷。问题现已解决。:)
public Brush UnderLineColor
{
get { return (Brush)GetValue(UnderLineColorProperty); }
set { SetValue(UnderLineColorProperty, value); }
}
public static readonly DependencyProperty UnderLineColorProperty =
DependencyProperty.Register("UnderLineColor", typeof(Brush), typeof(SectionHeader), null);