Xamarin Prism Model to ViewModel Fody

时间:2018-01-31 19:28:21

标签: c# mvvm xamarin.forms prism fody

如何使用Fody拦截从模型到ViewModel?

我尝试将它放在我的ViewModel中,但没有任何反应,我错过了什么吗? 我正在使用Xamarin Forms,Prism 模型

   public class Question : INotifyPropertyChanged
    {
        public bool IsValid { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            Debug.WriteLine("This Works Here :) ");
            var propertyChanged = PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

视图模型

public class MainPageViewModel : INavigationAware, INotifyPropertyChanged{
        public virtual void OnPropertyChanged(string propertyName)
        {
            Debug.WriteLine("It Does not reach here :( ");
        }

        public static void Intercept(object target, Action onPropertyChangedAction, string propertyName)
        {
            Debug.WriteLine("It Does not reach here too :( ");
            onPropertyChangedAction();
        }
}

我是否需要使用 PropertyChangedNotificationInterceptor ?如何在我的View-Model中实现它,任何建议都很棒

[UPDATE]

Sample of Repo here

1 个答案:

答案 0 :(得分:1)

在fody属性中进行更改的过程就这么简单:

public string Text{ get; set; }
public void OnTextChanged()
{
}