Xamarin form: How to reference to the parent binding

后端 未结 5 1858
情歌与酒
情歌与酒 2020-12-29 05:42
 
   
      
   

Ass

5条回答
  •  太阳男子
    2020-12-29 06:30

    even qubuss give the correct answer I like to answer this question with example to make it more clear

    lets consider we have a page

    this reference parent context
        x:Class="Your_Class_Name">
      
                
                   
                       
                            
                             // this come from item source
                        
                        

    your view Model should look like that

     public class ViewModelName 
        {
            private List _listSource = new List();
    
    
            public List ListSource
            {
                get => _listSource;
                set
                {
                    _listSource = value;
                    RaisePropertyChanged();
                }
            }
    
            public ICommand CommandFromParent => new Command(HandleYourActionHere);
    
    }
    }
    

    small Explanation of what happen , when we write BindingContext.CommandFromParent BindingContext represent BindingContext of firstPage(x:Name="firstPage") which be ViewModelName

提交回复
热议问题