DataTrigger where value is NOT null?

后端 未结 12 626
野趣味
野趣味 2020-11-27 10:56

I know that I can make a setter that checks to see if a value is NULL and do something. Example:


  
    

        
12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 11:18

    My solution is in the DataContext instance (or ViewModel if using MVVM). I add a property that returns true if the Not Null condition I want is met.

        Public ReadOnly Property IsSomeFieldNull() As Boolean
            Get
                Return If(SomeField is Null, True, False)
            End Get
        End Property
    

    and bind the DataTrigger to the above property. Note: In VB.NET be sure to use the operator If and NOT the IIf function, which doesn't work with Null objects. Then the XAML is:

        
          
        
    

提交回复
热议问题