WPF Binding isAsync Get State

I use the Binding IsAsync property to support the user interface and load data from the get accessor properties and it turned out to be a good option when using MVVM. This approach is wonderful and does not require any manual code for asynchronous operations. There are several cases where my dataload takes a few seconds, and during this time it is very difficult to distinguish between โ€œno dataโ€ and โ€œdata loadingโ€. Is there a property that I can detect the binding state of "IsBusy" or "Download" so that I can show a message that the download operation is not completed?

Any help is appreciated.

+6
asynchronous binding
source share
2 answers

According to the docs ,

While awaiting a value, the binding tells FallbackValue if available, or the default value for the target property of the binding.

You can use this value to display a message to the user during binding loading.

+7
source share

I know this is an old thread. But if someone is still interested ...

You can use PriorityBinding, there is an excellently explained example in this article: http://www.switchonthecode.com/tutorials/wpf-tutorial-priority-bindings

The idea is to specify a PriorityBinding, which in turn defines several regular bindings like this:

<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock.Text> <PriorityBinding> <Binding ElementName="MainWindow" Path="Slow" IsAsync="True" /> <Binding ElementName="MainWindow" Path="Fast" /> </PriorityBinding> </TextBlock.Text> </TextBlock> 

The order of bindings determines the priority with the highest priority. In this case, Fast binding (the lowest priority) will immediately fill in the text block, because you may have the "Loading ..." or "Sort ..." string property, depending on what is happening at that time, and eat without delay.

But later, when the property of slow asynchronous binding returns a value, a higher priority means that it will be accepted, since it is previously in the list, and its results will be bound instead, showing the actual results.

If you need to populate a progress popup, you can implement this in the getter of the related property in your ViewModel, although I have not tried anything like this.

+17
source share

All Articles