Windows 8 Metro: ListView ignores ItemTemplate

I am following this tutorial, but I ran into some strange problem. There is a part that says:

In SplitPage.xaml, we also update the ItemTemplate property in itemListView to use our DefaultListItemTemplate resource instead of Standard130ItemTemplate, which is the default template. Here's the updated XAML for itemListView.

However, no matter what I do, it displays a list with a default template that looks like this . Here is my code:

<DataTemplate x:Key="DefaultListItemTemplate"> <Grid HorizontalAlignment="Stretch" Width="Auto" Height="110" Margin="10,10,10,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <!-- Green date block --> <Border Background="{StaticResource BlockBackgroundBrush}" Width="110" Height="110" /> <ContentControl Template="{StaticResource DateBlockTemplate}" /> <StackPanel Grid.Column="1" HorizontalAlignment="Left" Margin="12,8,0,0"> <TextBlock Text="{Binding Title}" FontSize="26.667" TextWrapping="Wrap" MaxHeight="72" Foreground="#FFFE5815" /> <TextBlock Text="{Binding Author}" FontSize="18.667" /> </StackPanel> </Grid> </DataTemplate> 

... in Page.Resources and

 <ListView x:Name="itemListView" AutomationProperties.AutomationId="ItemsListView" AutomationProperties.Name="Items" TabIndex="1" Grid.Row="1" Margin="-10,-10,0,0" Padding="120,0,0,60" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" IsSwipeEnabled="False" SelectionChanged="ItemListView_SelectionChanged" ItemTemplate="{StaticResource DefaultListItemTemplate}"/> 

... on the Grid page.

I tried to embed the template and modify the Standard130ItemTemplate to no avail. However, specifying a nonexistent template throws a build error.

Any ideas what I can do wrong?

+4
source share
1 answer

Apparently, this was caused by a low screen resolution (1280x800). I did not notice that the Split Page template defines the following VisualState for FilledOrNarrow:

  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="ItemTemplate"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource Standard80ItemTemplate}"/> </ObjectAnimationUsingKeyFrames> 

I tried to run it in a simulator, and anything wider than it (e.g. 1366x768) works fine.

+4
source

All Articles