wpf error validation when binding is not two-way
I have a read only control that displays a calculation from other information in a datagrid. The binding it has works as far as displaying updated data as 开发者_开发百科cell entries are made.
I do need to show visually when the calculation is above a given threshold. It is a read-only control (label, actually) though. How can I go about doing this?
Cheers,
Berrylif there is a calculation object that has properties such as IsOutsideRange (to display validation) and CalculationText (to display the text) then you could use a DataTrigger as so, the label's datacontext would be set to the calculation object
<Label Text="{Binding Path=CalculationText}">
<Label.Style>
<Style
BasedOn="{StaticResource {x:Type Label}}"
TargetType="{x:Type Label}">
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsOutsideRange}"
Value="True">
<Setter
Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
精彩评论