C# Xamarin表单可绑定对象值更改事件

C# Xamarin表单可绑定对象值更改事件,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,我已经使用Xamarin表单映射创建了一个自定义映射。我想在VisibleRegion更改时访问更新的VisibleRegion 自定义渲染器 在自定义控件中,我创建了一个可绑定属性 MapCenterPosition.cs 现在我有了CustomMap并将其绑定到ViewModel代码。但是,当地图中心更新时,如何在ViewModel中触发某些方法?我犯了一个简单的错误 我所要做的就是在xaml中将绑定模式设置为双向 在自定义控件中,我应该替换这个 public MapCenterPositi

我已经使用Xamarin表单映射创建了一个自定义映射。我想在VisibleRegion更改时访问更新的VisibleRegion

自定义渲染器 在自定义控件中,我创建了一个可绑定属性 MapCenterPosition.cs
现在我有了CustomMap并将其绑定到ViewModel代码。但是,当地图中心更新时,如何在ViewModel中触发某些方法?

我犯了一个简单的错误

我所要做的就是在xaml中将绑定模式设置为双向

在自定义控件中,我应该替换这个

public MapCenterPosition MapCenter { get; set; }

现在我可以在每次MapCenter更新时触发视图模型中的方法

public MapCenterPosition MapCenter { get; set; }
public static readonly BindableProperty MapCenterProperty = BindableProperty.Create(
            nameof(MapCenter),
            typeof(MapCenterPosition),
            typeof(CustomMap),
            null);


public void OnMapRegionUpdated()
{
   MapCenter = new MapCenterPosition {Position = VisibleRegion.Center};
}
public class MapCenterPosition: INotifyPropertyChanged
{
    private Position _position;

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChange([CallerMemberName]string propertyname = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
    }

    public Position Position
    {
        get => _position;
        set 
        { 
            _position = value;
            RaisePropertyChange();
        }

    }
}
public MapCenterPosition MapCenter { get; set; }
public MapCenterPosition MapCenter
{
    get => (MapCenterPosition) GetValue(MapCenterProperty);
    set => SetValue(MapCenterProperty,value);
}