In MvvmLight, ho trovato che accanto a Messenger.Default che è una specie di variabile statica globale per memorizzare l'handle di messaggio dell'intera applicazione, ogni Viewmodel avrà un altro gestore di Messenger denominato MessengerInstance. Quindi, sono confuso su cosa sia MessengerInstance utilizzato per & come usarlo? (Solo ViewModel può vedere -> che riceverà & messaggio processo?)MessengerInstance vs Messenger.Default in Mvvmlight
5
A
risposta
3
Il MessengerInstance
viene utilizzato dal RaisePropertyChanged() Metodo:
<summary>
/// Raises the PropertyChanged event if needed, and broadcasts a
/// PropertyChangedMessage using the Messenger instance (or the
/// static default instance if no Messenger instance is available).
///
/// </summary>
/// <typeparam name="T">The type of the property that
/// changed.</typeparam>
/// <param name="propertyName">The name of the property
/// that changed.</param>
/// <param name="oldValue">The property's value before the change
/// occurred.</param>
/// <param name="newValue">The property's value after the change
/// occurred.</param>
/// <param name="broadcast">If true, a PropertyChangedMessage will
/// be broadcasted. If false, only the event will be raised.</param>
protected virtual void RaisePropertyChanged<T>(string propertyName, T oldValue, T
newValue, bool broadcast);
si può utilizzare su una proprietà su una vista modello B per esempio:
public const string SelectedCommuneName = "SelectedCommune";
private communes selectedCommune;
public communes SelectedCommune
{
get { return selectedCommune; }
set
{
if (selectedCommune == value)
return;
var oldValue = selectedCommune;
selectedCommune = value;
RaisePropertyChanged(SelectedCommuneName, oldValue, value, true);
}
}
Cattura e trattare con esso su un modello di vista a con:
Messenger.Default.Register<PropertyChangedMessage<communes>>(this, (nouvelleCommune) =>
{
//Actions to perform
Client.Ville = nouvelleCommune.NewValue.libelle;
Client.CodePays = nouvelleCommune.NewValue.code_pays;
Client.CodePostal = nouvelleCommune.NewValue.code_postal;
});
Spero che questo aiuti :)
Problemi correlati
- 1. MVVMLight ViewModelLocator registrazione Dataservice
- 2. Passare il parametro tra ViewModels utilizzando MVVMLight
- 3. EventToCommand non esiste nel toolkit Mvvmlight WPF4.5
- 4. MvvmLight EventToCommand e WPFToolkit DataGrid doppio clic
- 5. Navigazione delle pagine attraverso ViewModel usando MVVMLight in windows 8
- 6. Mvvmlight e Xamarin.iOS in grado di trovare di default ctor
- 7. MVVMLight - come ottenere un riferimento a ViewModel nella vista?
- 8. * vs ** vs *** in Proguard?
- 9. bigtable vs cassandra vs simpledb vs dynamo vs couchdb vs hypertable vs riak vs hbase, cosa hanno in comune?
- 10. Misurare il tempo in Linux - tempo vs orologio vs getrusage vs clock_gettime vs gettimeofday vs timespec_get?
- 11. limite vs esiste vs count (*) vs count (id) in MySQL
- 12. in linea vs __inline vs __inline__ vs __forceinline?
- 13. Int32 Int64 vs vs Int in C#
- 14. In goniometro, browser.isElementPresent vs element.isPresent vs element.isElementPresent
- 15. Elenco vs Set vs Borsa in NHibernate
- 16. link_to vs url_for vs percorso in Rails
- 17. Run vs. Content vs. Text in WPF
- 18. Il "Software installato" vs "Funzioni" vs "Plug-in" in Eclipse
- 19. VS 2013 MSTest vs nUnit vs xUnit
- 20. control.BeginInvoke() Vs Dispatcher Vs SynchronizationContext Vs .. - AFFIDABILITÀ
- 21. Exec vs ExecWait vs ExecShell vs nsExec :: Exec vs nsExec :: ExecToLog vs nsExec :: ExecToStack vs ExecDos vs ExeCmd
- 22. ACE vs Boost vs Poco vs wxWidgets
- 23. Atomikos vs JOTM vs Bitronix vs?
- 24. === vs. == in Ruby
- 25. + = vs = + in Java
- 26. SpiderMonkey vs JavaScriptCore vs?
- 27. ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID?
- 28. VS 2008 vs VS 2008 Express
- 29. .NET vs ASP.NET vs CLR vs ASP
- 30. Accumulare vs piega vs ridurre vs comprimere
Grazie! Chiaro ora!^_ ^ – kidgu