Silverlight 3 DataBinding with ValueConverter: conditionally use the default value for property
- by eriksmith200
I have a DatePicker for which I want to set the BorderBrush to SolidColorBrush(Colors.Red) if the SelectedDate is null. If a date has been filled in though, I want to just have the default BorderBrush. I still want to be able to style the default BorderBrush in Blend, so I don't want to hardcode the default borderbrush of the DatePicker. So basically:
xaml:
<controls:DatePicker BorderBrush="{Binding SelectedDate, RelativeSource={RelativeSource Self}, Converter={StaticResource BrushConverter}, Mode=OneWay}"/>
c#:
public class BrushConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return value == null ?
new SolidColorBrush(Colors.Red) : /* when value != null have the bound property use it's default value */
}
is this possible?