Hello guys,
I have a problem and a question regarding Xamarin.Forms and CollectionView. I implemented a CollectionView as a Main Menu and on Android it is working fine.
But on my iPhone it is not showing the CollectionView.
The ScrollView is showing I think because the LightBlue background is visible on my iPhone.
It is build for iOS 9 and Android 9.0 and with XCode 12.2.
Are there known issues with ObservableCollections, CollectionViews, some attributes or maybe someone can tell my what I did wrong.
This is how it looks on Android:
This is my xaml code and C# code:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FlyThePilotHelper.MainPage"
xmlns:local="clr-namespace:FlyThePilotHelper.ViewModels">
<ContentPage.BindingContext>
<local:MainPageViewModel/>
</ContentPage.BindingContext>
<ScrollView BackgroundColor="LightBlue">
<CollectionView Grid.Row="3" Grid.ColumnSpan="2" ItemsSource="{Binding AllMenuItems}"
SelectionMode="Single"
SelectedItem="{Binding SelectedMenuItem}"
SelectionChangedCommand="{Binding SelectedMenuItemChangedCommand}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="2" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10,10">
<Frame CornerRadius="50">
<Label x:Name="label1" Text="{Binding .}" FontSize="Title" WidthRequest="100"
VerticalTextAlignment="Center" HorizontalTextAlignment="Center"
HeightRequest="{Binding Width, Source={x:Reference label1}}"/>
</Frame>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ScrollView>
</ContentPage>
AllMenuItems = new ObservableCollection<string>
{
"Unit Conversions",
"Procedures",
"Wind Calculations",
"Fuel Calculations"
};
}
string selectedMenuItem;
public string SelectedMenuItem
{
get => selectedMenuItem;
set
{
selectedMenuItem = value;
var args = new PropertyChangedEventArgs(nameof(SelectedMenuItem));
PropertyChanged?.Invoke(this, args);
}
}