Я застрял в этой проблеме при первой попытке использовать формы xamarin.
Я пытаюсь установить DataTemplateSelector для CollectionView в формах Xamarin, но я получаю эту ошибку «LoadTemplate не должен быть нулевым».
Работает без проблем, если я использую ListView.
Это мой код XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodel="clr-namespace:JisrWallet.ViewModels"
xmlns:common="clr-namespace:JisrWallet.Common"
x:Class="JisrWallet.views.Layout.CardsPage"
xmlns:views="clr-namespace:SuaveControls.Views;assembly=SuaveControls.FloatingActionButton"
BackgroundColor="{StaticResource lightGray}">
<ContentPage.Resources>
<ResourceDictionary>
<common:IntColorToHexConverter x:Key="colorConverter"/>
<common:PrefixValueConverter x:Key="prefixConverter"/>
<DataTemplate x:Key="existCardTemplate">
<StackLayout Margin="2">
<Image Source="{Binding StoreImageUrl}"
Aspect="AspectFill"
HeightRequest="120"
BackgroundColor="{Binding CardColor, Converter={StaticResource colorConverter}}"/>
</StackLayout>
</DataTemplate>
<DataTemplate x:Key="newCardTemplate">
<StackLayout BackgroundColor="{Binding CardColor, Converter={StaticResource colorConverter}}">
<Label Text="{Binding CardName, Converter={StaticResource prefixConverter}, ConverterParameter=1}"
HeightRequest="120"
HorizontalOptions="Center"
VerticalOptions="Center"
VerticalTextAlignment="Center"
TextColor="White"/>
<Label Text="{Binding CardName}"
FontAttributes="Bold"
BackgroundColor="{Binding CardColor, Converter={StaticResource colorConverter}}"
TextColor="{StaticResource whiteColor}"
HorizontalTextAlignment="Center"/>
<BoxView HeightRequest="2" BackgroundColor="White"/>
</StackLayout>
</DataTemplate>
<common:CardItemTemplateSelector x:Key="cardItemTemplateSelector"
ExistCardTemplate="{StaticResource existCardTemplate}"
NewCardTemplate="{StaticResource newCardTemplate}"/>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
<StackLayout.BindingContext>
<viewmodel:CardsViewModel/>
</StackLayout.BindingContext>
<CollectionView x:Name="collectionView"
ItemsSource="{Binding Cards}"
ItemTemplate="{StaticResource newCardTemplate}"
SelectionMode="Single"
SelectionChanged="CollectionView_SelectionChanged">
<CollectionView.ItemsLayout >
<GridItemsLayout Orientation="Vertical" Span="2" />
</CollectionView.ItemsLayout>
</CollectionView>
<views:FloatingActionButton Image="ic_add_white"
ButtonColor="{StaticResource AccentColor}"
WidthRequest="56"
HeightRequest="56"
HorizontalOptions="End"
VerticalOptions="CenterAndExpand"
Margin="8"
Clicked="FloatingActionButton_Clicked"/>
</StackLayout>
</ContentPage>
Я не могу понять проблему.Кто-нибудь может мне помочь, пожалуйста?