I have created a ViewModel related to a custom Xamarin Forms Map
Over this Map, I am displaying an Entry field, on a trigger to be visible or invisible according to conditions
I have successfully bound the Entry IsVisible parameter to the behavior, and can toggle it on a button
However, what I actually want is to achieve this in response to the click on a Pin
When I attempt this, i cannot get the OnPropertyChange to fire
I'm not sure how to overcome this - the pin is in a separate class so I cannot bind it to the Grid view that contains the text entry
I've attached a click event to the custom pin and used it to interact with the view model
pin.Clicked += (object sender, EventArgs e) =>
{
var p = sender as CustomPin;
var callingMethod = new HandleEditor();
callingMethod.Pin_Clicked(p);
};
This is the XAML
<Grid x:Name="LayoutGrid">
<Grid.BindingContext>
<local:HandleEditor />
</Grid.BindingContext>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="150" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<local:CustomMap Grid.RowSpan="3" Grid.Row="0" MapType="Street" WidthRequest="300" HeightRequest="300" />
<Editor x:Name="TextEntry" Grid.Row="1" VerticalOptions="FillAndExpand" IsVisible="{Binding SwitchVisible, Mode=TwoWay}"/>
<Button Grid.Row="2" Text="Switch Bool Test" Command="{Binding ChangeBoolValue}"/>
</Grid>
This is the ViewModel
public event PropertyChangedEventHandler PropertyChanged;
bool isEditorVisible = false;
public ICommand ChangeBoolValue { protected set; get; }
public ICommand Debug { protected set; get; }
public bool SwitchVisible
{
get
{
System.Diagnostics.Debug.WriteLine("Debug: SwitchVisible has been fired " + isEditorVisible);
return isEditorVisible;
}
}
public HandleEditor()
{
ChangeBoolValue = new Command(() =>
{
if (isEditorVisible == true)
{
isEditorVisible = false;
OnPropertyChanged("SwitchVisible");
}
else
{
isEditorVisible = true;
OnPropertyChanged("SwitchVisible");
}
});
}
protected virtual void OnPropertyChanged(string propertyName)
{
System.Diagnostics.Debug.WriteLine("Debug: OnPropertyChanged has been fired " + propertyName + " : " + isEditorVisible);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void Pin_Clicked(CustomPin pin)
{
isEditorVisible = true;
OnPropertyChanged("SwitchVisible");
}