Example #1
0
        static void CreateDocRegion(LayoutDocument element, string regionName)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            //If I'm in design mode the main window is not set
            if (App.Current == null ||
                App.Current.MainWindow == null)
                return;

            try
            {
                if (ServiceLocator.Current == null)
                    return;

                // Build the region
                var mappings = ServiceLocator.Current.GetInstance<RegionAdapterMappings>();
                if (mappings == null)
                    return;
                IRegionAdapter regionAdapter = mappings.GetMapping(element.GetType());
                if (regionAdapter == null)
                    return;

                var region = regionAdapter.Initialize(element, regionName);

                var rm = ServiceLocator.Current.GetInstance<RegionManager>();
                rm.Regions.Add(region);
            }
            catch (Exception ex)
            {
                throw new RegionCreationException(string.Format("Unable to create region {0}", regionName), ex);
            }
        }