/// <summary>
        ///     Gets the sort index of an element.
        /// </summary>
        /// <param name="element"> The element. </param>
        /// <param name="indexInContainer"> The index of the element in its container or null if the index is not available. </param>
        /// <returns>
        ///     The sort index of the element.
        ///     <see cref="int.MaxValue" /> is returned if the element does not provide a sort index in any way.
        /// </returns>
        /// <remarks>
        ///     <para>
        ///         The sort index of an element is retrieved using <see cref="IRegionElement.SortIndex" /> (high priority),
        ///         <see cref="RegionElementSortHintAttribute" /> (medium priority), and the index of the element in the container
        ///         (if available, low priority).
        ///     </para>
        /// </remarks>
        protected virtual int GetSortIndex(object element, int?indexInContainer)
        {
            if (element is IRegionElement)
            {
                IRegionElement regionElement = (IRegionElement)element;

                if (regionElement.SortIndex.HasValue)
                {
                    return(regionElement.SortIndex.Value);
                }
            }

            object[] attributes = element.GetType()
                                  .GetCustomAttributes(typeof(RegionElementSortHintAttribute), true);

            if (attributes.Length != 0)
            {
                return(((RegionElementSortHintAttribute)attributes[0]).Index);
            }

            if (indexInContainer.HasValue)
            {
                return(indexInContainer.Value);
            }

            return(int.MaxValue);
        }
 /// <summary>
 ///     Navigates the specified element to its new container.
 /// </summary>
 /// <param name="container"> The new container. </param>
 /// <param name="element"> The new element. </param>
 protected virtual void NavigatedTo(object container, object element)
 {
     if (element is IRegionElement)
     {
         IRegionElement regionElement = (IRegionElement)element;
         regionElement.NavigatedTo();
     }
 }
        /// <summary>
        ///     Checks whether the specified element can be navigated to its new container.
        /// </summary>
        /// <param name="container"> The new container. </param>
        /// <param name="element"> The new element. </param>
        /// <returns>
        ///     true if the navigation is allowed, false otherwise.
        /// </returns>
        protected virtual bool CanNavigateTo(object container, object element)
        {
            if (element is IRegionElement)
            {
                IRegionElement regionElement = (IRegionElement)element;
                return(regionElement.CanNavigateTo());
            }

            return(true);
        }
        /// <inheritdoc />
        public virtual void Deactivate(object container, object element)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            if (element is IRegionElement)
            {
                IRegionElement regionElement = (IRegionElement)element;
                regionElement.Deactivated();
            }
        }