[英]Multiple item template inside grid view in Windows 8.1 store app
In a gridview item template , is it possible to have multiple templates ? 在gridview项目模板中,是否可以有多个模板? In my screen i am having set of icons in a single section of GridView control.
在我的屏幕上,我在GridView控件的单个部分中有一组图标。 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.
我如何自定义它,以便使大量项目具有不同尺寸的网格。
Yes, you can. 是的你可以。 You need a DataTemplateSelector .
您需要一个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: 在XAML中:
<Page.Resources>
<local:TemplateSelectorMyPage x:Key="mySelector"
BigIconTemplate="{StaticResource myBigIconTemplate}"
NormalIconTemplate="{StaticResource myNormalIconTemplate}">
</local:TemplateSelectorBusinessPage>
</Page.Resources>
In the Grid XAML: 在网格XAML中:
<GridView
x:Name="itemGridView"
ItemTemplateSelector="{StaticResource mySelector}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.