Xamarin form: How to reference to the parent binding

@qubuss gave the correct answer below, but I would like to give more context and show an example to make it more clear:

Lets consider the following page:

<ContentPage  
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Name="firstPage" -->this reference parent context
    x:Class="Your_Class_Name">
  <ListView x:Name="ListSource"
            ItemsSource="{Binding ListSource}" >
            <ListView.ItemTemplate>
               <DataTemplate>
                   <ViewCell>
                        <Grid>
                         // this come from item source
                    <Label Text="{Binding ABC}"></Label>
                    <Button Command="{Binding BindingContext.CommandFromParent
                           , Source={x:Reference firstPage} }" />
                        </Grid>
                                                
                       </ViewCell>
                  /DataTemplate>
           </ListView.ItemTemplate>
    </ListView>


</ContentPage>

your view Model should look like that

 public class ViewModelName 
    {
        private List<YourDataType> _listSource = new List<YourDataType>();
        

        public List<YourDataType> ListSource
        {
            get => _listSource;
            set
            {
                _listSource = value;
                RaisePropertyChanged();
            }
        }

        public ICommand CommandFromParent => new Command(HandleYourActionHere);

}
}

Explanation
When we write BindingContext.CommandFromParent, BindingContext represents the BindingContext of firstPage(x:Name="firstPage") which is of type ViewModelName

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)