Reputation: 4906
I am making a WPF application using an MVVM architecture. For each site, the database keeps a foreground a background colour value, which on mapping from the database, creates 2 new instances of System.Windows.Media.Brush which correspond to those colours.
the viewmodel then wraps the selected site like so:
public Brush TextBrush
{
get
{
if (StudyCentre == null)
{
return _defaultText;
}
return StudyCentre.TextColour;
}
}
I am also defining a style for validation errors, which I think might be pertinent to the error:
<Style x:Key="errorStyle" TargetType="TextBlock">
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="Red" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Margin" Value="0,1" />
</Style>
<DataTemplate DataType="{x:Type ValidationError}">
<TextBlock Style="{StaticResource errorStyle}" Text="{Binding Path=ErrorContent}" />
</DataTemplate>
and setting the foreground colour like so:
<Style TargetType="TextBlock" >
<Setter Property="Foreground" Value="{Binding Path=TextBrush, Mode=OneWay}" />
</Style>
however, the output is full of the following error (that is think one for every validation contentcontrol
System.Windows.Data Error: 40 : BindingExpression path error: 'TextBrush' property not found on 'object' ''ValidationError' (HashCode=26199139)'. BindingExpression:Path=TextBrush; DataItem='ValidationError' (HashCode=26199139); target element is 'TextBlock' (Name=''); target property is 'Foreground' (type 'Brush')
the page displays fine (I don't want the foreground colour to apply to the textblocks within the error contentcontrols), but I would like to avoid this binding error.
Is there a way to exclude the error content controls, while still applying to textboxes without resorting to named styles? thanks.
Upvotes: 0
Views: 227
Reputation: 69985
I don't believe that you can remove that entry from the Output Window, but you can 'downgrade' it from a System.Windows.Data Error
to a System.Windows.Data Warning
by setting a valid FallbackValue
:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground"
Value="{Binding Path=TextBrush, FallbackValue=Black}" />
</Style>
Upvotes: 1