You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am migrating a Xamarin Forms app using MessageCenter to WeakReferenceMessenger. The messages are used within a control. I need to be able to distinguish messages sent from a instance of a control given that I can have multiple instances of this control on a page. How do I replace the following code: MessagingCenter.Subscribe(this, "AutoSuggestBox_" + nameof(SuggestionChosen), (AutoSuggestBox box, object selectedItem) => { if (box == this) RaiseSuggestionChosen(selectedItem); });
I tried the following code: WeakReferenceMessenger.Default .Register<AutoSuggestBox, SuggestionChosenNotification>(this, (r, m) => { if (r == this) RaiseSuggestionChosen(m.Value); });
The check for the AutoSuggestBox control instance isn't working. I am trying to determine if the message received is for this control instance. What is the proper way to implement this? With the current code all control instances display this message because : if (r == this)
is not equivalent to : if (box == this)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am migrating a Xamarin Forms app using MessageCenter to WeakReferenceMessenger. The messages are used within a control. I need to be able to distinguish messages sent from a instance of a control given that I can have multiple instances of this control on a page. How do I replace the following code:
MessagingCenter.Subscribe(this, "AutoSuggestBox_" + nameof(SuggestionChosen), (AutoSuggestBox box, object selectedItem) => { if (box == this) RaiseSuggestionChosen(selectedItem); });
I tried the following code:
WeakReferenceMessenger.Default .Register<AutoSuggestBox, SuggestionChosenNotification>(this, (r, m) => { if (r == this) RaiseSuggestionChosen(m.Value); });
The check for the AutoSuggestBox control instance isn't working. I am trying to determine if the message received is for this control instance. What is the proper way to implement this? With the current code all control instances display this message because :
if (r == this)
is not equivalent to :
if (box == this)
Beta Was this translation helpful? Give feedback.
All reactions