@@ -348,12 +348,14 @@ ReadOnlyObservableCollection<MostRecentlyUsedFileItem> mruList = mruManager.Most
348
348
349
349
----
350
350
### ` EventAggregator `
351
- Dynamic implementation of the EventAggregator design pattern. Listen to events broadcasted by a specific type or by a specific event or by matching event handler signature.
351
+ Dynamic implementation of the EventAggregator design pattern.
352
+ Listen to broadcasted events by a specific source type, by a specific event name, by matching event handler signature or by matching ` EventArgs ` type.
353
+
352
354
Allows to listen to an event without the need to reference the source instance.
353
355
354
356
#### Example
355
357
##### Aggregate events
356
- Let the ` EventAggregator ` subscribe to events :
358
+ Register event sources with an instance of ` EventAggregator ` :
357
359
358
360
``` C#
359
361
var aggregator = new EventAggregator ();
@@ -379,8 +381,8 @@ aggregator.TryRegisterObservable(
379
381
new [] {nameof (INotifyPropertyChanged .PropertyChanged )});
380
382
```
381
383
382
- ##### Listen to * all * aggregated event sources * by event name *
383
- Subscribe to the ` EventAggregator ` and listen to specific events of ** all** aggregated event sources:
384
+ ##### Listen to events by name, raised by any aggregated event source
385
+ Subscribe to the ` EventAggregator ` and listen to ** specific events** of ** all event sources** :
384
386
385
387
``` C#
386
388
// Listen to everything that publishes the 'INotifyPropertyChanged.PropertyChanged' event
@@ -389,8 +391,8 @@ aggregator.TryRegisterObserver<PropertyChangedEventHandler>(
389
391
ShowMessage_OnPropertyChanged );
390
392
```
391
393
392
- ##### Listen to * specific * aggregated event sources by event name
393
- Subscribe to the ` EventAggregator ` and listen to specific events of ** specific** aggregated event sources (by source type):
394
+ ##### Listen to events by name, raised by all event sources that match a specific type (e.g., class or interface)
395
+ Subscribe to the ` EventAggregator ` and listen to ** specific events** of ** specific event sources** (by source type):
394
396
395
397
``` C#
396
398
// Only listen to the 'INotifyPropertyChanged.PropertyChanged' event raised by any instance of type 'MainWindowViewModel'
@@ -399,29 +401,30 @@ aggregator.TryRegisterObserver<PropertyChangedEventHandler>(
399
401
mainWindowViewModel .GetType (),
400
402
ShowMessage_OnPropertyChanged );
401
403
402
- // Only listen to the 'INotifyPropertyChanged.PropertyChanged' event of all instances that implement 'IPage'
404
+ // Only listen to the 'INotifyPropertyChanged.PropertyChanged' event of all instances that implement 'IPage' interface
403
405
aggregator .TryRegisterObserver <PropertyChangedEventHandler >(
404
406
nameof (INotifyPropertyChanged .PropertyChanged ),
405
407
typeof (IPage ),
406
408
ShowMessage_OnPropertyChanged );
409
+
407
410
```
408
411
##### Listen to all events that match the signature of the event handler or that use a matching ` EventArgs ` type
409
412
410
- Subscribe to the ` EventAggregator ` and listen to all events that have an event delegate with matching signature:
413
+ Subscribe to the ` EventAggregator ` and listen to all events that have an ** event delegate with matching signature** :
411
414
``` C#
412
415
413
416
// Subscribe by defining the event delegate explicitly
414
417
aggregator .TryRegisterGlobalObserver (new PropertyChangedEventHandler (ShowMessage_OnPropertyChanged ));
415
418
```
416
419
417
- Subscribe to the ` EventAggregator ` and listen to all events that use a matching ` EventArgs ` type:
420
+ Subscribe to the ` EventAggregator ` and listen to all events that use a ** matching ` EventArgs ` type** :
418
421
419
422
``` C#
420
423
// Subscribe by defining the EventArgs as generic type parameter
421
424
aggregator .TryRegisterGlobalObserver <PropertyChangedEventArgs >(ShowMessage_OnPropertyChanged );
422
425
```
423
426
424
- ##### Type declarations used in examples
427
+ ##### Type declarations used in above examples
425
428
426
429
``` C#
427
430
// Event callback
0 commit comments