Share via


Windows 8 Application and OData with Netflix

Windows 8 and OData goes hand in hand. Today while discussing with my sweetheart, I started working on this demo on how to consume OData with Windows 8 Style Application. It does not follow the UX design guideline. However, an honest attempt to demonstrate the capability.

I have used the most famous Netflix OData from https://odata.netflix.com/v2/Catalog/

So I have created the Blank Windows Store application

image

Then have added the reference

image

If you get an error, then most probably the WCF Component is not installed. Follow the error message and download from the link

image

After that add the below XAML in MainPage.xaml

 <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <Button x:Name="btnLoad" Content="Load Them" Grid.Row="0" FontSize="36" Click="btnLoad_Click"></Button>
    <ListBox x:Name="lstData" Grid.Row="1">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Image Stretch="Uniform" Height="100" Width="100" Margin="3,0">
                        <Image.Source>
                            <BitmapImage UriSource="{Binding Path=BoxArt.LargeUrl}"></BitmapImage>
                        </Image.Source>
                    </Image>
                    <TextBlock Text="{Binding Path=Name}"></TextBlock>
                        
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

After that C# Code would look like,

 NetFlixSvc.NetflixCatalog context = new NetFlixSvc.NetflixCatalog(new Uri(@"https://odata.netflix.com/v2/Catalog/", UriKind.RelativeOrAbsolute));
DataServiceCollection<NetFlixSvc.Title> _titles;

public void LoadData()
{
    _titles = new DataServiceCollection<NetFlixSvc.Title>();
    var query = context.Titles;
    _titles.LoadAsync(query);
    _titles.LoadCompleted += _titles_LoadCompleted;
}
void _titles_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
    lstData.ItemsSource = _titles;
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
    LoadData();            
}

The output looks like,

image

I am again telling that this violets the basic Windows 8 Style Application design guideline.

Namoskar!!!

Comments

  • Anonymous
    September 18, 2012
    Good Article.

  • Anonymous
    September 18, 2012
    Glad Srikanth

  • Anonymous
    September 18, 2012
    does Netflix allow you access webservice in India??