コード例 #1
0
        /// <summary>
        /// Method that will create the region, by calling the right <see cref="IRegionAdapter"/>.
        /// </summary>
        /// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param>
        /// <param name="regionName">Name of the region.</param>
        /// <returns>The created <see cref="IRegion"/></returns>
        protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
        {
            if (targetElement == null)
            {
                throw new ArgumentNullException(nameof(targetElement));
            }

            try
            {
                // Build the region
                IRegionAdapter regionAdapter = this._regionAdapterMappings.GetMapping(targetElement.GetType());
                IRegion        region        = regionAdapter.Initialize(targetElement, regionName);

                return(region);
            }
            catch (Exception ex)
            {
                throw new RegionCreationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "An exception occurred while creating a region with name '{0}'. The exception was: {1}.",
                              regionName,
                              ex),
                          ex);
            }
        }
コード例 #2
0
ファイル: RegionManager.cs プロジェクト: eslahi/prism
        /// <summary>
        /// Attaches a region to an object and adds it to the region manager.
        /// </summary>
        /// <param name="regionTarget">The object to adapt. This is typically a container (i.e a control).</param>
        /// <param name="regionName">The name of the region to register.</param>
        /// <exception cref="ArgumentException">When regions collection already has a region registered using <paramref name="regionName"/>.</exception>
        public void AttachNewRegion(object regionTarget, string regionName)
        {
            if (Regions.ContainsKey(regionName))
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.RegionNameExistsException, regionName));

            IRegionAdapter regionAdapter = regionAdapterMappings.GetMapping(regionTarget.GetType());
            IRegion region = regionAdapter.Initialize(regionTarget);

            Regions.Add(regionName, region);
        }
コード例 #3
0
        /// <summary>
        /// Method that will create the region, by calling the right <see cref="IRegionAdapter"/>.
        /// </summary>
        /// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param>
        /// <param name="regionName">Name of the region.</param>
        /// <returns>The created <see cref="IRegion"/></returns>
        protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
        {
            try
            {
                // Build the region
                IRegionAdapter regionAdapter = this.regionAdapterMappings.GetMapping(targetElement.GetType());
                IRegion        region        = regionAdapter.Initialize(targetElement, regionName);

                return(region);
            }
            catch (Exception ex)
            {
                throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Resources.RegionCreationException, regionName, ex), ex);
            }
        }
コード例 #4
0
        static void CreateRegionWithRegionAdapter(DependencyObject element, string regionName)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            //If I'm in design mode the main window is not set
            if (Application.Current == null ||
                Application.Current.MainWindow == null)
            {
                return;
            }
            var shellView = ServiceLocator.Current.GetInstance <ShellView>();

            if (shellView == null)
            {
                throw new ArgumentNullException("AvalonDockRegion.shellView");
            }
            shellView.Loaded += (sender, e) =>
            {
                //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;
                    }

                    regionAdapter.Initialize(element, regionName);
                }
                //catch (Exception ex)
                //{
                //    throw new RegionCreationException(string.Format("Unable to create region {0}", regionName), ex);
                //}
            };
        }
コード例 #5
0
        /// <summary>
        /// Method that will create the region, by calling the right <see cref="IRegionAdapter"/>.
        /// </summary>
        /// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param>
        /// <param name="regionName">Name of the region.</param>
        /// <returns>The created <see cref="IRegion"/></returns>
        protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
        {
            if (targetElement == null)
            {
                throw new ArgumentNullException("targetElement");
            }
            try
            {
                // Build the region
                IRegionAdapter regionAdapter = this.regionAdapterMappings.GetMapping(targetElement.GetType());
                IRegion        region        = regionAdapter.Initialize(targetElement, regionName);

                return(region);
            }
            catch (Exception ex)
            {
                throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Application.Current.FindResource("RegionCreationException").ToString(), regionName, ex), ex);
            }
        }
コード例 #6
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);
            }
        }