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
You could check the following code
Since you had used Custom ContentView , you need use bindable property to binding value between the elements in ContentView and Parent ContentPage
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView
x:Class="Acies.NitroT.Views.Home.AddressChipView"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:behaviors="clr-namespace:Acies.NitroT.Behaviors"
xmlns:buttons="clr-namespace:Syncfusion.XForms.Buttons;assembly=Syncfusion.Buttons.XForms"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:Acies.NitroT.Controls;assembly=Acies.NitroT.Mobile.Shared"
mc:Ignorable="d"
x:Name="ChipView" // set the name of AddressChipView
>
<buttons:SfChipGroup
ChipPadding="2,0,0,0"
Command="{Binding Source={x:Reference ChipView}, Path=SelectedAddressCommand}"
//...
SelectedItem="{Binding Source={x:Reference ChipView}, Path=SelectedAddress}"
ShowIcon="True"
Type="Choice">
<buttons:SfChipGroup.Behaviors>
<behaviors:EventToCommandBehavior
Command="{Binding Source={x:Reference ChipView}, Path=AddressSelectionChangedCommand}"
CommandParameter="{Binding Source={x:Reference ChipView}, Path=CurrentMapView}"
EventName="SelectionChanged" />
</buttons:SfChipGroup.Behaviors>
</buttons:SfChipGroup>
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
<homeViews:AddressChipView Grid.Row="1" AddressSelectionChangedCommand={Binding xxxCommand} CurrentMapView = {Binding Source={x:Reference Map}, Path=.} />