Check whether the binding property exists or not
Asked Answered
B

1

7

I've a situation in which there is a common control which is used couple of places in application.

Now in this i've a data trigger on a property say A. i.e.

DataTrigger Binding={Binding A} .......

Now it may be possible that property A doesn't exist in view model, in that case i need to add another trigger based on property B (which exist in that ViewModel).

Something like:

Multidatatrigger

DataTrigger Binding A - doesn't exist
DataTrigger Binding B  

Do something.....

Can someone suggest me how i should approach for this. . As if i try to do as such then binding exception will be thrown because A doesn't exist in current View Model. Or any other approach would work here... Thanks

Bloodmobile answered 12/7, 2011 at 14:14 Comment(0)
B
14

You can make use of PriorityBinding.

<DataTrigger Value="XXX">
  <DataTrigger.Binding>
     <PriorityBinding>
        <Binding Path="A"/>
        <Binding Path="B"/>
     </PriorityBinding>
  </DataTrigger.Binding>
  <Setter ...
</DataTrigger>
Benetta answered 12/7, 2011 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.