Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Binding FallbackValue set to Binding

Is there a way to have another binding as a fallback value?

I'm trying to do something like this:

<Label Content="{Binding SelectedItem.Name, ElementName=groupTreeView,                          FallbackValue={Binding RootGroup.Name}}" /> 

If anyone's got another trick to pull it off, that would be great.

like image 715
HaxElit Avatar asked Dec 16 '09 15:12

HaxElit


1 Answers

What you are looking for is something called PriorityBinding (#6 on this list)

(from the article)

The point to PriorityBinding is to name multiple data bindings in order of most desirable to least desirable. This way if the first binding fails, is empty and/or default, another binding can take it's place.

e.g.

<TextBox>     <TextBox.Text>         <PriorityBinding>             <Binding Path="LastNameNonExistant" IsAsync="True" />             <Binding Path="FirstName" IsAsync="True" />         </PriorityBinding>     </TextBox.Text> </TextBox> 
like image 77
kiwipom Avatar answered Sep 20 '22 20:09

kiwipom