PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms 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//===================================================================================
17using System.Collections.Specialized;
18using Microsoft.Practices.Composite.Regions;
19using StockTraderRI.Infrastructure;
20using StockTraderRI.Modules.Watch.WatchList;
21
22namespace StockTraderRI.Modules.Watch.Controllers
23{
24    public class WatchListController : IWatchListController
25    {
26        private readonly IRegionManager regionManager;
27        private readonly IWatchListPresentationModel watchListPresentationModel;
28
29        public WatchListController(IRegionManager regionManager, IWatchListPresentationModel watchListPresentationModel)
30        {
31            this.regionManager = regionManager;
32            this.watchListPresentationModel = watchListPresentationModel;
33        }
34
35        public void Run()
36        {
37            this.regionManager.RegisterViewWithRegion(
38                                                    RegionNames.MainRegion,
39                                                    () => this.watchListPresentationModel.View);
40            this.watchListPresentationModel.WatchListItems.CollectionChanged += this.WatchController_CollectionChanged;
41        }
42
43        private void WatchController_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
44        {
45            if (e.Action == NotifyCollectionChangedAction.Add)
46            {
47                var mainRegion = this.regionManager.Regions[RegionNames.MainRegion];
48                if (mainRegion != null)
49                {
50                    mainRegion.Activate(this.watchListPresentationModel.View);
51                }
52            }
53        }
54    }
55}