Mvvmcross Plugins - Cirrious.MvvmCross.Plugins.Messenger

zhhao418發表於2014-08-03

定義所傳送訊息的內容:

public class LoginMessage : MvxMessage
 {
        public LoginMessage(object sender, string userName)
                : base(sender)
            {
                UserName = userName;
            }

            public string UserName { get; private set; }
}


傳送訊息:

LoginMessage message = new LoginMessage(this, UserName);

 Mvx.Resolve<IMvxMessenger>().Publish(message); 


接收訊息:

private MvxSubscriptionToken _token;

 _token = Mvx.Resolve<IMvxMessenger>().Subscribe<LoginMessage>(OnLoginMessage);


接收到訊息所觸發的事件:

  private void OnLoginMessage(LoginMessage loginMessage)
   {
            txtUserName.Text = loginMessage.UserName;
    }

相關文章