How to bind a CommandParameter in a ContentView to an element in the parent ContentPage in Xamarin Forms

后端 未结 1 399
别那么骄傲
别那么骄傲 2021-01-17 04:32

I have a parent ContentPage with several ContentViews in separate files. I am trying to pass as reference an element in the parent ContentView to a CommandParameter in one

1条回答
  •  情歌与酒
    2021-01-17 04:57

    You could check the following code

    in AddressChipView.xaml

    Since you had used Custom ContentView , you need use bindable property to binding value between the elements in ContentView and Parent ContentPage

    
    
    
    
                    
                        
                    
                
    

    in AddressChipView.xaml.cs

    public static readonly BindableProperty AddressSelectionChangedCommandProperty =
                BindableProperty.Create(nameof(AddressSelectionChangedCommand), typeof(ICommand), typeof(AddressChipView));
    
            public ICommand AddressSelectionChangedCommand
            {
                get => (ICommand)GetValue(AddressSelectionChangedCommandProperty );
                set => SetValue(AddressSelectionChangedCommandProperty , value);
            }
    
            public static BindableProperty CurrentMapViewProperty =
                BindableProperty.Create(nameof(CurrentMapView), typeof(object), typeof(AddressChipView));
    
            public object CurrentMapView
            {
                get => (object)GetValue(CurrentMapViewProperty );
                set => SetValue(CurrentMapViewProperty , value);
            }
    
            //... other bindable property  
           
    

    Now you can binding it in ContentPage

    
    

    0 讨论(0)
提交回复
热议问题