I am trying to associate some data with a GridView
element in a Windows 8.1 Hub
.
I currently have a DataTemplate
configured under Page.Resources
as follows:
<DataTemplate x:Key="Standard240x320ItemTemplateFAV"> <Grid HorizontalAlignment="Left" Width="320" Height="240"> <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}"> <Image Source="{Binding FavImage}" Stretch="UniformToFill"/> </Border> <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}"> <TextBlock Text="{Binding FavTitle}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextBlockStyle}" Height="48" Margin="15,0,15,0"/> </StackPanel> </Grid> </DataTemplate>
Then I have a HubSection
:
<HubSection x:Name="FavHub" Padding="40,60,40,0" > <DataTemplate> <GridView x:Name="itemGridView" Margin="-4,-4,0,0" AutomationProperties.AutomationId="ItemGridView" AutomationProperties.Name="Items In Group" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource Standard240x320ItemTemplateFAV}" SelectionMode="Single" IsSwipeEnabled="false" IsItemClickEnabled="True" ItemClick="ItemView_ItemClick"> </GridView> </DataTemplate> </HubSection>
I use this code to add a DataContext:
FavHub.DataContext = new FavData(Constants.getImage("1002"), "No Favourites");
Where is the FavData class:
public class FavData { public static string FavImage { get; set; } public static string FavTitle { get; set; } public FavData() { } public FavData(string itemImageSet, string itemNameSet) { FavImage = itemImageSet; FavTitle = itemNameSet; } }
However, the HubSection does not display data. What am I doing wrong?
source share