【发布时间】:2021-07-19 18:17:47
【问题描述】:
我正在像这样夸大数据模板选择器:
<ContentPage.Resources>
<ResourceDictionary>
<local:MyDataTemplateSelector x:Key="templateSelector"></local:MyDataTemplateSelector>
</ResourceDictionary>
</ContentPage.Resources>
<Grid Grid.Row="0" >
<abstractions:CarouselViewControl VerticalOptions="Start" x:Name="carouselview" ItemTemplate="{StaticResource templateSelector}" />
</Grid>
代码如下所示:
public MyDataTemplateSelector()
{
Layout1 = new DataTemplate(typeof(CV_CarouselView_ShowPics));
Layout2 = new DataTemplate(typeof(CV_VideoPlayer));
}
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
FullAdType cell = (FullAdType)item;
if(cell != null && cell.hasVideo )
{
return Layout2; // get video layout
}
else
return Layout1;
}
但是数据模板选择器的构造函数在 iOS 上都没有被调用,但在 Android 上,它工作得很好。
这里有什么问题?
谢谢
【问题讨论】:
-
DataTemplate应该在 xaml 中定义,我们不需要模板选择器构造函数,检查docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/…。 -
然而,它在 android 中被调用,而在 iOS 上没有任何显示...
标签: ios xamarin.forms