Reputation: 2022
In a gridview item template , is it possible to have multiple templates ? In my screen i am having set of icons in a single section of GridView control. I wqant to have one of the icon to have a larger dimension. How can i achive it.
<GridView>
<GridView.ItemTemplate>
<DataTemplate>
<Grid/>
<DataTemplate/>
<GridView.ItemTemplate/>
<GridView/>
In this template the dimension igive for the grid will remain same for all the elements. How can i customize it so that onne of the item have a grid of different dimension.
Upvotes: 0
Views: 777
Reputation: 4490
Yes, you can. You need a DataTemplateSelector. You can select an appropriate template for the selected object in the grid/list.
Sample for selector:
class TemplateSelectorMyPage : DataTemplateSelector
{
public DataTemplate NormalIconTemplate { get; set; }
public DataTemplate BigIconTemplate { get; set; }
protected override DataTemplate SelectTemplateCore( object item, DependencyObject container )
{
var uiElement = container as UIElement;
if( uiElement == null )
{
return base.SelectTemplateCore( item, container );
}
if ( item is BigIconItem )
{
return BigIconTemplate;
}
else if ( item is NormalIconItem )
{
return NormalIconTemplate;
}
return base.SelectTemplateCore( item, container );
}
In the XAML:
<Page.Resources>
<local:TemplateSelectorMyPage x:Key="mySelector"
BigIconTemplate="{StaticResource myBigIconTemplate}"
NormalIconTemplate="{StaticResource myNormalIconTemplate}">
</local:TemplateSelectorBusinessPage>
</Page.Resources>
In the Grid XAML:
<GridView
x:Name="itemGridView"
ItemTemplateSelector="{StaticResource mySelector}"
Upvotes: 2