开发者

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,

Berryl


if 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜