Forms DataTemplateSelector在iOS上不起作用(未调用构造函数)

Forms DataTemplateSelector在iOS上不起作用(未调用构造函数),ios,xamarin.forms,Ios,Xamarin.forms,我正在膨胀数据模板选择器,如下所示: <ContentPage.Resources> <ResourceDictionary> <local:MyDataTemplateSelector x:Key="templateSelector"></local:MyDataTemplateSelector> </ResourceDictionary> </ContentPage.Reso

我正在膨胀数据模板选择器,如下所示:

<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>
但这两个数据模板选择器和构造函数都不是在iOS上调用的,而是在Android上,它可以正常工作

这里的问题是什么


谢谢

我们经常在xaml中定义
数据模板


DataTemplate
应该在xaml中定义,我们不需要模板选择器构造函数,请检查。它在android中调用,在iOS上没有显示任何内容…即使我这样做,iOS也不会返回任何内容。选择模板上的任何内容都不会被调用。您介意共享一个基本的、最小的项目给我们测试吗?由于它在侧面工作正常,所以构造函数按预期调用。我发现了一个问题:这个:没问题,如果您有任何其他问题,请告诉我。
    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;

    }
 <ContentPage.Resources>
        <DataTemplate x:Key="AmericanMonkeyTemplate">
            ...
        </DataTemplate>

        <DataTemplate x:Key="OtherMonkeyTemplate">
            ...
        </DataTemplate>

        <controls:MonkeyDataTemplateSelector x:Key="MonkeySelector"
                                             AmericanMonkey="{StaticResource AmericanMonkeyTemplate}"
                                             OtherMonkey="{StaticResource OtherMonkeyTemplate}" />
    </ContentPage.Resources>

    <CarouselView ItemsSource="{Binding Monkeys}"
                  ItemTemplate="{StaticResource MonkeySelector}" />
public PersonDataTemplateSelector()
        {
            ValidTemplate = new DataTemplate(()=> {

                var grid = new Grid();

                var nameLabel = new Label { FontAttributes = FontAttributes.Bold };
                nameLabel.TextColor = Color.Green;
                nameLabel.SetBinding(Label.TextProperty, "Name");
                grid.Children.Add(nameLabel);

                return grid ;
            });

            InvalidTemplate = new DataTemplate(() => {

                var grid = new Grid();

                var nameLabel = new Label {  };
                nameLabel.TextColor = Color.Red;
                nameLabel.SetBinding(Label.TextProperty, "Name");
                grid.Children.Add(nameLabel);

                return grid ;
            });

        }