コード例 #1
0
        static void CreateRegion(LayoutAnchorable element, string regionName)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            //If I'm in design mode the main window is not set
            if ((bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
            {
                return;
            }

            try
            {
                if (Microsoft.Practices.ServiceLocation.ServiceLocator.Current == null)
                {
                    return;
                }

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

                regionAdapter.Initialize(element, regionName);
            }
            catch (Exception ex)
            {
                throw new RegionCreationException(string.Format("Unable to create region {0}", regionName), ex);
            }
        }