Need advice on binding to use Commands

Lloyd Sheen 1,481 Reputation points
2023-12-22T18:58:36.1+00:00

I have a ContentPage which has two ContentViews, the whole thing has one ViewModel.

In one of the views there is a CollectionView and in the DataTemplate for the items it has a Lable with a TapGestureRecognizer. Now that TapGestureRecognizer has an ICommand which handles the tap and this is where I have a problem.

I had to define the Command in the Class that is the Item. That works but is where the problem is. The tap event needs to set an ItemsSource and I have had to define the CollectionView as the parameter to the Command event in order for it to know where to set the ItemsSource.

What is the way (or is there a good way) to be able to do this without all the references to controls. The same problem would occur if I use the ViewModel property to bind the ItemsSource.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,006 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.