WPF Reflections

Oct 25 2007   3:43PM GMT

Priority binding

Mark Shurmer Profile: MarkWPF

This is quite a useful binding helper when you are in a scenario where you have a binding to a slow value.
What I mean by that is that sometimes a value may appear in your data source slowly because it is being created via a remote service for example, especially if in the scenario you cannot determine when the value will be received back.

What this markup extension allows you to do is specify a list of bindings, like this:

<TextBlock.Text>
      <PriorityBinding FallbackValue="default text" >
       <Binding Path="Slowest" IsAsync="True">
       <Binding Path="Medium" IsAsync="True">
       <Binding Path="Fast" >
  </PriorityBinding>
</TextBlock.Text>

In this example, assume the slowest takes 8 seconds, the Medium 5 seconds and the Fast is merely nanoseconds
WPF will try the slowest first, but as it’s not there move on to the medium one. That’s not there either so it moves on to the last one, and as that is very fast it will display that one.

What’s even better is that WPF will then display the Medium one after 5 seconds and the slow one after 8 seconds!

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: