I was trying to nest a collectionView inside another, but I am having troubles when it comes to binding the ItemsSource property of the nested one, even though the method by which I have created the ObservableCollection and binded it to the ItemsSource property is the same for both collectionViews. Any idea what am I doing wrong?
XAML code:
<ContentPage.Resources>
<ResourceDictionary>
<selectors:FirstSelector x:Key="First"/>
<selectors:SecondSelector x:Key="Second"/>
</ResourceDictionary>
</ContentPage.Resources>
<renderers:GradientLayout
ColorsList="#FFFFFF,#FFFFFF"
Mode="ToBottomLeft"
Padding="10,50,10,0">
<ScrollView>
<StackLayout>
<CollectionView
ItemsSource="{Binding FirstList}"
ItemTemplate="{StaticResource First}"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Margin="0,0,0,15">
<CollectionView.ItemsLayout>
<LinearItemsLayout
Orientation="Vertical"
ItemSpacing="15"/>
</CollectionView.ItemsLayout>
<CollectionView.Resources>
<DataTemplate x:Key="Normal">
<Grid
HeightRequest="400"
HorizontalOptions="FillAndExpand"
ColumnDefinitions="20*,30*,25*,25*"
RowDefinitions="15*,70*,15*">
<Frame
Padding="0"
HasShadow="False"
BackgroundColor="Pink"
CornerRadius="30"
IsClippedToBounds="True"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4">
<CollectionView
ItemTemplate="{StaticResource Second}"
ItemsSource="{Binding SecondList}"
BackgroundColor="Blue"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<CollectionView.ItemsLayout>
<LinearItemsLayout
Orientation="Horizontal"
ItemSpacing="0">
</LinearItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.Resources>
<DataTemplate x:Key="NormalTwo">
<Grid
WidthRequest="392"
BackgroundColor="Orange"
ColumnDefinitions="100*"
RowDefinitions="100*"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Padding="0">
<Frame
BackgroundColor="Purple"
HasShadow="False"
CornerRadius="20"
Padding="0"
Grid.Column="0"
Grid.Row="0">
<Image
Margin="-2,0,0,0"
Source="source.jpg"
Aspect="AspectFill"
HeightRequest="200">
</Image>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.Resources>
</CollectionView>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.Resources>
</CollectionView>
</StackLayout>
</ScrollView>
</renderers:GradientLayout>
ViewModel code:
public class HomeViewModel : FreshBasePageModel
{
public static ObservableCollection<OneForAllModel> firstlist;
public ObservableCollection<OneForAllModel> FirstList
{
get
{
return pictureList;
}
set
{
pictureList = value;
}
}
public ObservableCollection<PictureModel> secondlist;
public ObservableCollection<PictureModel> SecondList
{
get
{
return secondcollectionlist;
}
set
{
secondcollectionlist = value;
}
}
public HomeViewModel(InavigationService _navigation, IDatabaseApiHelper _DataBaseApi)
{
Navigation = _navigation;
DataBaseApi = _DataBaseApi;
//Creates a provisional list necessary to show the skeleton loading UI effect
OneForAllModel loadingPicture = new OneForAllModel()
{
//content
};
ObservableCollection<OneForAllModel> LoadingList = new ObservableCollection<OneForAllModel>()
{
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
loadingPicture,
};
//This list is binded to the first collection view item source and works perfectly
FirstList = LoadingList;
#region SecondCollectionViewBelongins
PictureModel a = new PictureModel()
{
//content
};
PictureModel b = new PictureModel()
{
//content
};
ObservableCollection<PictureModel> list = new ObservableCollection<PictureModel>()
{
a,
b
};
SecondList = list;
**//This second binding does not seem to work**
#endregion
}
That is all, if you need more information I will provide it as soon as I see your request, thank you all so much for your time, have a good day.