Exemple #1
0
        public void ShowDlg()
        {
            if (_panel.Children.Count == 0)
            {
                foreach (var mi in _mi.Items)
                {
                    _panel.Children.Add(mi);
                }
            }

            if (_mi.Owner.IsContextMenu)
            {
                if (Kit.IsPhoneUI)
                {
                    PhonePlacement = DlgPlacement.FromBottom;
                }
                else
                {
                    // 默认放右侧,不能完全显示放左侧
                    if (_mi.GetBounds().Right + MinWidth > SysVisual.ViewWidth)
                    {
                        WinPlacement = DlgPlacement.TargetOuterLeftTop;
                    }
                    else
                    {
                        WinPlacement = DlgPlacement.TargetTopRight;
                    }
                }
            }
            else
            {
                if (Kit.IsPhoneUI)
                {
                    PhonePlacement = (_mi.ParentMi == null) ? DlgPlacement.TargetBottomLeft : DlgPlacement.FromBottom;
                }
                else
                {
                    // 一级放左下方,多级默认放右侧,不能完全显示放左侧
                    if (_mi.ParentMi == null && !_mi.Owner.IsContextMenu)
                    {
                        WinPlacement = DlgPlacement.TargetBottomLeft;
                    }
                    else if (_mi.GetBounds().Right + MinWidth > SysVisual.ViewWidth)
                    {
                        WinPlacement = DlgPlacement.TargetOuterLeftTop;
                    }
                    else
                    {
                        WinPlacement = DlgPlacement.TargetTopRight;
                    }
                }
            }

            Closed -= OnClosed;
            if (_mi.ParentMi == null || Kit.IsPhoneUI)
            {
                Closed += OnClosed;
            }
            Show();
        }