Esempio n. 1
0
        /// <summary>
        /// Opens the current instance of the <see cref="RadRadialMenu"/>.
        /// </summary>
        internal void Open()
        {
            if (this.TargetElement != null)
            {
                var behavior = RadRadialContextMenu.GetBehavior(this.TargetElement);

                if (behavior != null)
                {
                    behavior.AttachToTargetElement();
                }
            }

            this.model.ShowView();

            if (this.TargetElement != null)
            {
                PopupService.DisplayOverlay();
            }

            this.CalculateRingsAspectRatio();

            if (this.model.viewState.StartAngleLevels.Count > 0)
            {
                this.model.Layout.StartAngle = this.model.viewState.StartAngleLevels[0];
                this.model.UpdateRingsRadius();
            }
        }
        private void Owner_LayoutUpdated(object sender, object e)
        {
            var menu = RadRadialContextMenu.GetMenu(this.Owner);

            if (menu != null)
            {
                menu.LayoutUpdated -= this.Owner_LayoutUpdated;
                this.PositionMenu(menu);
            }
        }
        protected internal virtual void DetachFromTargetElement()
        {
            var menu = RadRadialContextMenu.GetMenu(this.Owner);

            if (menu != null)
            {
                menu.TargetElement = null;
            }

            PopupService.Detach();
        }
        /// <summary>
        /// It is used to detach the previous <see cref="RadRadialMenu"/> owner control.
        /// </summary>
        /// <param name="previousOwner"></param>
        protected override void OnDetached(FrameworkElement previousOwner)
        {
            if (previousOwner != null)
            {
                this.UnsubscribeFromTargetEvents(previousOwner);

                var menu = RadRadialContextMenu.GetMenu(previousOwner);

                if (menu != null)
                {
                    menu.LayoutUpdated -= this.Owner_LayoutUpdated;
                }

                base.OnDetached(previousOwner);
            }
        }
        /// <summary>
        /// It is used to position the <see cref="RadRadialMenu"/> and initiate menu position logic.
        /// </summary>
        protected internal virtual void AttachToTargetElement()
        {
            if (this.Owner == null)
            {
                return;
            }

            var menu = RadRadialContextMenu.GetMenu(this.Owner);

            if (menu != null && (PopupService.CurrentAttachedMenu != menu ||
                                 (PopupService.CurrentAttachedMenu != null && PopupService.CurrentAttachedMenu.TargetElement != this.Owner)))
            {
                menu.model.actionService.PushAction(
                    new DelegateAction(() =>
                {
                    if (menu.TargetElement != null)
                    {
                        var behavior = RadRadialContextMenu.GetBehavior(menu.TargetElement);

                        if (behavior != null)
                        {
                            behavior.DetachFromTargetElement();
                        }
                        else
                        {
                            this.DetachFromTargetElement();
                        }
                    }

                    menu.TargetElement = this.Owner;

                    PopupService.Attach(menu);

                    if (menu.DesiredSize.Height == 0 || menu.DesiredSize.Width == 0)
                    {
                        menu.LayoutUpdated += this.Owner_LayoutUpdated;
                    }
                    else
                    {
                        this.PositionMenu(menu);
                    }
                }));
            }
        }
Esempio n. 6
0
        public static void SetBehavior(DependencyObject obj, RadialMenuTriggerBehavior value)
        {
            var oldBehavior = RadRadialContextMenu.GetBehavior(obj);
            var element     = obj as FrameworkElement;

            if (oldBehavior != null && element != null)
            {
                oldBehavior.Owner = null;
            }

            if (obj != null)
            {
                obj.SetValue(BehaviorProperty, value);
            }

            if (value != null && element != null)
            {
                value.Owner = element;
            }
        }