Forum Xamarin Xamarin.Forms

How to know which class the view cell is called from?

ArunGupta.7607ArunGupta.7607 USMember ✭✭
edited June 2018 in Xamarin.Forms

I have a common ViewCell which multiple ListView's in different ContentPage use. Now in ViewCell xaml.cs file i want to know which class invoked this ViewCell. Is it possible to find this?

Here is my sceanrio. I have added ContextActions to the ViewCell. Now what i want is based on the ContentPage/ViewModel which invokes this View Cell the ContextActions Text should change to either Cancel, Add, More... So how can i identify which class in ViewCell so that ContextActions text can be changed?

I am using MVVM so can the ContextActions Text Property binded with ViewModel property?

Best Answer


  • EricSchmeckEricSchmeck DEMember ✭✭
    Hi, you could make a sub class like CustomViewCell which inherits from ViewCell. In the constructor give the object your ListView as reference.
  • ArunGupta.7607ArunGupta.7607 USMember ✭✭

    Also i used below method to find which ViewModel class is used

    if (this.Parent.BindingContext.GetType() == typeof(TestViewModel))
    ContextMenuItem.Text = "Cancel";

Sign In or Register to comment.