I have a slow data source, so I create it asynchronously. Also, many properties of my viewmodel are themselves slow. Hence, I make them asynchronous too (binding to a Telerik property grid):
<Grid>
<Grid.DataContext>
<ObjectDataProvider ObjectType="{x:Type viewModels:MyViewModel}"
IsAsynchronous="True" x:Name="myViewModel" />
</Grid.DataContext>
<telerik:RadPropertyGrid x:Name="settings" Item="{Binding IsAsync=True}">
<telerik:RadPropertyGrid.PropertyDefinitions>
<telerik:PropertyDefinition
Binding="{Binding Path=SlowProperty,IsAsync=True,Mode=TwoWay}" />
</telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>
</Grid>
When debugging, I can see that the data source is indeed created in another thread, hence not blocking the UI. However, when I get into SlowProperty the debugger reveals that I’m still in the Main Thread – which is proven by the fact that the UI hangs until the property returns.
Q: What am I missing here? Isn’t IsAsync sufficient for asynchronous properties?
Edit: It seems this works for a normal TextBlock. Is the IsAsync behavior dependent on the implementation of a control? (In this case I suspect a bug in the property grid.)
You are always ecouraged to use
IsAsyncBindingwithPriorityBinding. GUI will wait until property is executed. But withPriorityBindingit will check if the firstBindingproperty isslow, if so, it will select the next placeholder binding (which should be fast). But when the slow property is evaluated, it would become the active value by the binding.In your case, you can simply set some
defaultValueinstead of giving multiple bindings.