Trong MvvmLight, tôi thấy rằng bên cạnh Messenger.Default là một loại biến tĩnh toàn cầu để lưu trữ xử lý tin nhắn của toàn bộ ứng dụng, mỗi ViewModel sẽ có một Trình xử lý Messenger khác có tên là MessengerInstance. Vì vậy, tôi đang nhầm lẫn về MessengerInstance được sử dụng cho & làm thế nào để sử dụng nó? (Chỉ ViewModel có thể nhìn thấy nó -> ai sẽ nhận & nhắn quá trình?)MessengerInstance vs Messenger.Default trong Mvvmlight
5
A
Trả lời
3
Các MessengerInstance
được sử dụng bởi RaisePropertyChanged() phương pháp:
<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);
Bạn có thể sử dụng nó trên một tài sản trên một cái nhìn mô hình B ví dụ:
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);
}
}
Catch nó và đối phó với nó trên một mô hình điểm A với:
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;
});
Hy vọng điều này sẽ giúp :)
Các vấn đề liên quan
- 1. MVVMLight ViewModelLocator đăng ký DataService
- 2. Điều hướng trang thông qua ViewModel sử dụng MVVMLight trong windows 8
- 3. MVVMLight - cách nhận tham chiếu đến ViewModel trong Chế độ xem?
- 4. Int32 vs Int64 vs Int trong C#
- 5. Exec vs ExecWait vs ExecShell vs nsExec :: Exec vs nsExec :: ExecToLog vs nsExec :: ExecToStack vs ExecDos vs ExeCmd
- 6. ACE vs Boost vs Poco vs wxWidgets
- 7. J2ME VS Android VS iPhone VS Symbian VS Windows CE
- 8. bigtable vs cassandra vs simpledb vs dynamo vs couchdb vs hypertable vs riak vs hbase, họ có điểm gì chung?
- 9. NetSqlAzMan vs AzMan vs (?????)
- 10. & vs * và | vs +
- 11. link_to vs url_for vs đường dẫn trong Rails
- 12. Danh sách vs Bộ vs Túi trong NHibernate
- 13. Guards vs if-then-else vs trường hợp trong Haskell
- 14. afterLayout vs layout, afterRender vs render, vv trong ExtJS?
- 15. Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc
- 16. getchar_unlocked() VS scanf() VS cin
- 17. Cache VS Session VS cookies?
- 18. HttpRequest vs HttpRequestMessage vs HttpRequestBase
- 19. DataView.RowFilter Vs DataTable.Select() vs DataTable.Rows.Find()
- 20. Delegate.CreateDelegate vs DynamicMethod vs Biểu
- 21. migrator.net vs fluentmigrator vs migsharp
- 22. UrlByAppendingPathComponent vs UrlByAppendingPathComponent vs UrlByAppendingPathExtension
- 23. ScheduledExecutorService vs Timer vs Handler
- 24. flume vs kafka vs others
- 25. Hiệu suất của GridView vs DataList vs Repeater vs ListView
- 26. Mongoose.model vs Connection.model vs Model.model
- 27. cụm vs Lưới vs Mây
- 28. MySQL vs Firebird vs SQLite
- 29. Selenium vs. SimpleTest vs. WatiN
- 30. EF ICollection Vs Danh sách Vs IEnumerable Vs IQueryable
Cảm ơn! Xóa ngay!^_ ^ – kidgu