现在的位置: 首页 > 综合 > 正文

lightswitch conditional formatting change color

2012年02月03日 ⁄ 综合 ⁄ 共 963字 ⁄ 字号 评论关闭

BTW, the best way to do a conditional color setting in LS beta 2 is to use the new SetBinding method. 

For example:

      Me.FindControl("MyControl").SetBinding(TextBox.BackgroundProperty, "Value", New ColorConverter(), BindingMode.OneWay)

  Public Class ColorConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
      If CType(value, Integer) > 20 Then
        Return New SolidColorBrush(Colors.Orange)
      End If
      Return New SolidColorBrush(Colors.Yellow)
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack

      Throw New NotImplementedException()
    End Function
  End Class

 

This will assign the background color to Orange when the value is great than 20.  With this code, we don't have to write extra code to monitor when the value is changed, and change the color again.

抱歉!评论已关闭.