Hi Everyone,
I am working on a app that has load in same xamarin forms pages. my first CollectionView consists of items in a data template what I need help with is when the user clicks a item in the data template collection view it loads them to a different CollectionView in the same page. How to do that? Here's my code :
<CollectionView.ItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
Answers
CollectionView in same page :
<CollectionView.ItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
Try to detect the SelectionChanged event of the first collectionView to get the selected item data, then add data to the collection which has been set binding to the second collectionView's ItemsSource.
Check the code:
The above solution also can be done. But I'd created another solution. Using,
public class MainCategoryVM : BaseVM
{
public MainCategoryVM(INavigation navigation)
{SelectCategoryChangedCommand = new Command((model) => SelectedCategoryChangedCommand(model));}
public Command SelectCategoryChangedCommand { get; }
public ObservableCollection Categories { get; set; }
private void SelectedCategoryChangedCommand(CategoryList model)
{
SelectCategory(model);
}
void SelectCategory(CategoryList model)
{
CategoriesDetail = new ObservableCollection();
}
public partial class MainPage : ContentPage
{
public MainPage ()
{
InitializeComponent ();
BindingContext = new MainCategoryVM(Navigation);
}
}
@fira If you've solved the issue, please mark your solution as the answer. It'll help others who face the similar problem. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.