2017-08-17 10 views
0

MainActivityからPCLビューにデータを返送しようとしています。データなしでメッセージを送信すると受信します。しかし、文字列を渡すと、コードに到達することはありません。 MainActivityでAndroidからPCLにデータが渡されたときにMessagingCenterメッセージが受信されない

:PCLで

if(data != null) 
      { 

       MessagingCenter.Send<object, string>(this, data, "MapIntentReceived"); 
       MessagingCenter.Send<object>(this, "MapIntentReceived"); 

      } 

:助けを

  MessagingCenter.Subscribe<object, string>(this, "MapIntentReceived", 
       async (sender, roomString) => 
       { //his code is not reached 
        await SearchForRooms(roomString); 
       }); 

      MessagingCenter.Subscribe<object>(this, "MapIntentReceived", 
       async (sender) => 
       { //this code is reached 
        await SearchForRooms("blah"); 
       }); 

感謝。

答えて

0

引数を指定してメッセージを送信するには、Generic型のパラメーターと、引数の値をSendメソッド呼び出しに含めます。

MessagingCenter.Send<MainPage, string> (this, "MapIntentReceived", data); 

メッセージで引数を渡すには、Subscribe汎用引数とアクションシグネチャで引数Typeを指定します。メッセージはMainActivityから来て退会

MessagingCenter.Unsubscribe<MainPage, string> (this, "MapIntentReceived"); 
+0

については

MessagingCenter.Subscribe<MainPage, string> (this, "MapIntentReceived", (sender, arg) => { await SearchForRooms(arg); }); 

、私は戻って汎用オブジェクトを渡している理由である、メインページではありません。しかし、間違ったパラメータの箇所にデータ文字列を渡していることを指摘しました。これが私の問題を解決しました。ありがとう! –

+0

@WillNasbyでは、MainPageの代わりに任意のオブジェクトを使用できます。 –

関連する問題