Monday, 9 September 2013

Is there a well-defined pattern for binding controls to asynchronous data?

Is there a well-defined pattern for binding controls to asynchronous data?

Can you tell whether the following snippets are correctly binding to an
asynchronous data source ?
While it seems to be working, i.e : UI does not freeze, I'm not entirely
sure about the correctness as the MSDN documentation does not really talk
about binding to 'async' methods in these docs :
Binding.IsAsync
ObjectDataProvider.IsAsynchronous
<pages:HottestPageProxy x:Key="PageProxy" ></pages:HottestPageProxy>
<ObjectDataProvider x:Key="DataProviderArtists" IsAsynchronous="True"
ObjectInstance="{StaticResource PageProxy}" MethodName="GetArtists">
<ObjectDataProvider.MethodParameters>
<system:String>Grabbing artists !</system:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ItemsControl x:Name="ItemsControlTopHott"
ItemsSource="{Binding Source={StaticResource DataProviderArtists},
Path=Result.Artists, IsAsync=True}">
</ItemsControl>
(HottestPageProxy object is a small helper that provides data for the
controls)
public class HottestPageProxy
{
[UsedImplicitly]
public async Task<ArtistsQuery> GetArtists([CallerMemberName] string
memberName = "")
{
Console.WriteLine(memberName);
string apiKey = App.GetApiKey();
Task<ArtistsQuery> topHottt = Queries.ArtistTopHottt(new
ArtistTopHotttParameters
{
ApiKey = apiKey,
Results = 100,
Buckets = new[] {ArtistTopHotttBuckets.Hotttnesss}
});
return (await topHottt);
}
}

No comments:

Post a Comment