如何使xamarin.forms 4.3与С相同;艾瑞斯佩奇?
文档中说我应该使用页面旋转木马,这是一个旋转木马视图。但我不明白如何做到这一点。 我有三个完全不同的页面。如果早些时候我能这样做。看看这有多容易如何使xamarin.forms 4.3与С相同;艾瑞斯佩奇?,xamarin.forms,Xamarin.forms,文档中说我应该使用页面旋转木马,这是一个旋转木马视图。但我不明白如何做到这一点。 我有三个完全不同的页面。如果早些时候我能这样做。看看这有多容易 <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/for
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselPage.Children>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</CarouselPage.Children>
现在,当我试图使外观与旋转木马完全相同时,我只有一个白色屏幕
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselView>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<local:View1></local:View1>
<local:View2></local:View2>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage>
人们告诉我应该有一个itemSource。如果没有itemSource,将不会显示内容。但据我所知,itemSource不允许您对数据进行不同的布局
我不明白如何从СarouselView(或CollectionView)复制СarouselPage,如果:
据我所知,您正在寻找的是
DataTemplateSelector
创建选择器的子类,其属性包含模板:
public class PersonDataTemplateSelector : DataTemplateSelector
{
public DataTemplate ValidTemplate { get; set; }
public DataTemplate InvalidTemplate { get; set; }
protected override DataTemplate OnSelectTemplate (object item, BindableObject container)
{
return ((Person)item).DateOfBirth.Year >= 1980 ? ValidTemplate : InvalidTemplate;
}
}
将它们添加到您的资源中:
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="validPersonTemplate">
<ViewCell>
...
</ViewCell>
</DataTemplate>
<DataTemplate x:Key="invalidPersonTemplate">
<ViewCell>
...
</ViewCell>
</DataTemplate>
<local:PersonDataTemplateSelector x:Key="personDataTemplateSelector"
ValidTemplate="{StaticResource validPersonTemplate}"
InvalidTemplate="{StaticResource invalidPersonTemplate}" />
</ResourceDictionary>
</ContentPage.Resources>
有关详细信息,请查看microsoft文档:
ItemTemplate="{StaticResource personDataTemplateSelector}"