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 IsAsync
Binding
with PriorityBinding
. GUI will wait until property is executed. But with PriorityBinding
it will check if the first Binding
property is slow
, 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.
<TextBlock>
<TextBlock.Text>
<PriorityBinding FallbackValue="defaultvalue">
<Binding Path="SlowestProp" IsAsync="True"/>
<Binding Path="SlowerProp" IsAsync="True"/>
<Binding Path="SurelyFastProp" />
</PriorityBinding>
</TextBlock.Text>
</TextBlock>
In your case, you can simply set some defaultValue
instead of giving multiple bindings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With