main
 1using System;
 2using System.Collections.Generic;
 3using System.Windows;
 4using gorilla.utility;
 5
 6namespace solidware.financials.windows.ui.views
 7{
 8    public partial class ShellWindow : RegionManager
 9    {
10        readonly IDictionary<Type, UIElement> regions;
11
12        public ShellWindow()
13        {
14            InitializeComponent();
15            regions = new Dictionary<Type, UIElement>
16                      {
17                          {GetType(), this},
18                          {typeof (Window), this},
19                          {Tabs.GetType(), Tabs},
20                          {StatusBar.GetType(), StatusBar},
21                          {Menu.GetType(), Menu},
22                          {SelectedFamilyMember.GetType(), SelectedFamilyMember},
23                      };
24        }
25
26        public void region<Region>(Action<Region> configure) where Region : UIElement
27        {
28            ensure_that_the_region_exists<Region>();
29            configure(regions[typeof (Region)].downcast_to<Region>());
30        }
31
32        public void region<Region>(Configuration<Region> configuration) where Region : UIElement
33        {
34            region<Region>(x => configuration.configure(x));
35        }
36
37        void ensure_that_the_region_exists<Region>()
38        {
39            if (!regions.ContainsKey(typeof (Region)))
40                throw new Exception("Could not find region: {0}".format(typeof (Region)));
41        }
42    }
43}