【问题标题】:Xamarin Prism Model to ViewModel FodyXamarin Prism 模型到 ViewModel Fody
【发布时间】:2018-01-31 19:28:21
【问题描述】:

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

我尝试将它放入我的 ViewModel 中,但没有任何反应,我错过了什么吗? 我正在使用 Xamarin 表单,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 中实现它,任何建议都会很棒

[更新]

Sample of Repo here

【问题讨论】:

  • 确保您的目标平台项目中有一个 Weavers.xml,其中包含
  • 我之前的评论有错别字,xml文件名应该是:“FodyWeavers.xml”。可能与github.com/Fody/Fody/issues/363 有关
  • @EvZ 谢谢,但不是这样,我在我的问题中添加了一个示例回购

标签: c# mvvm xamarin.forms prism fody


【解决方案1】:

在 fody 属性更改中调用就这么简单:

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

【讨论】:

  • 谢谢,当我还是个菜鸟的时候就提出了这个问题:),我从来没有意识到你必须让 Modal 本身可绑定
猜你喜欢
  • 1970-01-01
  • 2017-01-05
  • 1970-01-01
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 2017-10-19
  • 1970-01-01
  • 2017-06-16
相关资源
最近更新 更多