【问题标题】:How to pass parameters from viewmodel to viewmodel in wph8.1wph8.1中如何将参数从viewmodel传递给viewmodel
【发布时间】:2016-07-28 05:22:36
【问题描述】:

如何在 wph8.1 中将参数从一个视图模型传递和获取到另一个视图模型我正在使用如下 INavigationService 但我不知道如何从另一个视图模型获取参数。

  _Navigate.Navigate(typeof(nextView),data);

【问题讨论】:

    标签: windows-phone-8 windows-phone-8.1 mvvm-light


    【解决方案1】:

    您可以使用Messenger 在视图模型之间传递数据。 Messenger 就是为此而生的。

    发送消息:

    MessengerInstance.Send(payload, token);
    

    接收消息

    MessengerInstance.Register<PayloadType>(
    this, token, payload => SomeAction(payload));
    

    查看模型 1

    MessengerInstance.Send(Brushes.Red, MessengerToken.BrushChanged);
    

    查看模型 2

    class ViewModel()
    {
     // put this line in the constructor
      MessengerInstance.Register<Brush>(this, token, brush => ChangeColor(brush))
    }
    
    //Receive here 
    public void ChangeColor(Brush brush)
    {
      Brush = brush;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2021-08-31
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多