Sunday, March 5, 2017

WPF Tip #2 - Using FallbackValue with Async WPF Bindings

In Tip #1, we examined how an IsAsync attribute can be added to WPF bindings to allow an application's UI to remain responsive while waiting for long-running ViewModel property getters.

It was mentioned that setting the FallbackValue on an object provides a way to put a default value into a property while waiting for the live data to populate through the ViewModel. This can be used to populate actual default values or to display some placeholder text to indicate to users that the live data is still loading.

Here is a simple example of using a FallbackValue with IsAsync on a standard WPF TextBox bound to a ViewModel property named SlowText.

<TextBox Text="{Binding Path=SlowText, IsAsync=True, FallbackValue='Loading data from a slow connection...'}"/>

This will display "Loading data from a slow connection…" until the real data is returned from the SlowText property.

In Tip #3, we will look at the use of FallbackValue with MultiBinding.

 

del.icio.us Tags: ,

No comments:

Post a Comment