PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/V2.2/trunk/RI/Desktop/StockTraderRI.Modules.WatchList/Controllers/WatchListController.cs

#
C# | 55 lines | 35 code | 4 blank | 16 comment | 4 complexity | 5c62897bdaf1aa5c7a447c325ed7880b MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System.Collections.Specialized;
  18. using Microsoft.Practices.Composite.Regions;
  19. using StockTraderRI.Infrastructure;
  20. using StockTraderRI.Modules.Watch.WatchList;
  21. namespace StockTraderRI.Modules.Watch.Controllers
  22. {
  23. public class WatchListController : IWatchListController
  24. {
  25. private readonly IRegionManager regionManager;
  26. private readonly IWatchListPresentationModel watchListPresentationModel;
  27. public WatchListController(IRegionManager regionManager, IWatchListPresentationModel watchListPresentationModel)
  28. {
  29. this.regionManager = regionManager;
  30. this.watchListPresentationModel = watchListPresentationModel;
  31. }
  32. public void Run()
  33. {
  34. this.regionManager.RegisterViewWithRegion(
  35. RegionNames.MainRegion,
  36. () => this.watchListPresentationModel.View);
  37. this.watchListPresentationModel.WatchListItems.CollectionChanged += this.WatchController_CollectionChanged;
  38. }
  39. private void WatchController_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  40. {
  41. if (e.Action == NotifyCollectionChangedAction.Add)
  42. {
  43. var mainRegion = this.regionManager.Regions[RegionNames.MainRegion];
  44. if (mainRegion != null)
  45. {
  46. mainRegion.Activate(this.watchListPresentationModel.View);
  47. }
  48. }
  49. }
  50. }
  51. }