in XamlControlsGallery/ControlPages/GridViewPage.xaml.cs [50:124]
private void ItemTemplate_Checked(object sender, RoutedEventArgs e)
{
var tag = (sender as FrameworkElement).Tag;
if (tag != null)
{
string template = tag.ToString();
ContentGridView.ItemTemplate = (DataTemplate)this.Resources[template];
itemTemplate.Value = template;
if (template == "ImageTemplate")
{
DisplayDT.Value = @"<!-- ImageTemplate: -->
<DataTemplate x:Key='ImageTemplate' x:DataType='local1: CustomDataObject'>
<Image Stretch = 'UniformToFill' Source = '{x:Bind ImageLocation}'
AutomationProperties.Name = '{x:Bind Title}' Width = '190' Height = '130'
AutomationProperties.AccessibilityView = 'Raw'/>
</DataTemplate> ";
}
else if (template == "IconTextTemplate")
{
DisplayDT.Value = @"<!-- IconTextTemplate: -->
<DataTemplate x:Key='IconTextTemplate' x:DataType='local1:CustomDataObject'>
<RelativePanel AutomationProperties.Name='{x:Bind Title}' Width='280' MinHeight='160'>
<Image x:Name='image'
Width='18'
Margin='0,4,0,0'
RelativePanel.AlignLeftWithPanel='True'
RelativePanel.AlignTopWithPanel='True'
Source='{x:Bind ImageLocation}'
Stretch='Uniform' />
<TextBlock x:Name='title' Style='{StaticResource BaseTextBlockStyle}' Margin='8,0,0,0'
Text='{x:Bind Title}' RelativePanel.RightOf='image' RelativePanel.AlignTopWithPanel='True'/>
<TextBlock Text='{x:Bind Description}' Style='{StaticResource CaptionTextBlockStyle}'
TextWrapping='Wrap' Margin='0,4,8,0' RelativePanel.Below='title' TextTrimming='WordEllipsis'/>
</RelativePanel>
</DataTemplate>";
}
else if (template == "ImageTextTemplate")
{
DisplayDT.Value = @"<!-- ImageTextTemplate: -->
<DataTemplate x: Key = 'ImageTextTemplate' x: DataType = 'local1:CustomDataObject'>
<Grid AutomationProperties.Name = '{x:Bind Title}' Width = '280'>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = 'Auto'/>
<ColumnDefinition Width = '*'/>
</Grid.ColumnDefinitions>
<Image Source = '{x:Bind ImageLocation}' Height = '100' Stretch = 'Fill' VerticalAlignment = 'Top'/>
<StackPanel Grid.Column = '1' Margin = '8,0,0,8'>
<TextBlock Text = '{x:Bind Title}' Style = '{ThemeResource SubtitleTextBlockStyle}' Margin = '0,0,0,8'/>
<StackPanel Orientation = 'Horizontal'>
<TextBlock Text = '{x:Bind Views}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
<TextBlock Text = ' Views ' Style = '{ThemeResource CaptionTextBlockStyle}'/>
</StackPanel>
<StackPanel Orientation = 'Horizontal'>
<TextBlock Text = '{x:Bind Likes}' Style = '{ThemeResource CaptionTextBlockStyle}'/>
<TextBlock Text = ' Likes' Style = '{ThemeResource CaptionTextBlockStyle}'/>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>";
}
else
{
DisplayDT.Value = @"<!-- TextTemplate: -->
<DataTemplate x:Key='TextTemplate' x:DataType='local1: CustomDataObject'>
<StackPanel Width = '240' Orientation = 'Horizontal'>
<TextBlock Style = '{StaticResource TitleTextBlockStyle}' Margin = '8,0,0,0' Text = '{x:Bind Title}'/>
</StackPanel>
</DataTemplate>";
}
}
}