示例#1
0
        public void OpenView(IView view)
        {
            // 避免重复添加视图
            if (ViewList.Contains(view))
            {
                return;
            }

            ViewList.Add(view);

            var control = view as Control;

            control.Name = view.ID;
            if (control is IBarSupport)
            {
                var barSupport = control as IBarSupport;
                control.Enter += (s, e) =>
                {
                    var bars = barSupport.ExtendBars;
                    if (bars.IsNotNullOrEmpty())
                    {
                        foreach (var bar in bars)
                        {
                            this.BarExtend.Merge(bar);
                            this.BarItemSelectedObject.Caption    = view.Caption;
                            this.BarItemSelectedObject.Glyph      = view.Icon;
                            this.BarItemSelectedObject.LargeGlyph = view.LargeIcon;
                        }
                    }
                    if (this.BarExtend.VisibleLinks.Count > 1)
                    {
                        this.BarExtend.Visible = true;
                    }
                    else
                    {
                        this.BarExtend.Visible = false;
                    }
                };
                control.Leave += (s, e) =>
                {
                    this.BarExtend.UnMerge();
                    this.BarExtend.Visible = false;
                };
            }

            var groupItem = LayoutControlGroupRoot.AddGroup();

            groupItem.Name                   = view.ID;
            groupItem.Text                   = view.Caption;
            groupItem.CaptionImage           = view.Icon;
            groupItem.CustomizationFormText  = view.Caption;
            groupItem.TextLocation           = DevExpress.Utils.Locations.Top;
            groupItem.Padding                = new DevExpress.XtraLayout.Utils.Padding(0);
            groupItem.AllowCustomizeChildren = false;

            var layoutControlItem = groupItem.AddItem();

            layoutControlItem.Name  = view.ID;
            layoutControlItem.Text  = view.Caption;
            layoutControlItem.Image = view.Icon;
            layoutControlItem.CustomizationFormText = view.Caption;
            layoutControlItem.Control                 = control;
            layoutControlItem.TextLocation            = DevExpress.Utils.Locations.Top;
            layoutControlItem.TextVisible             = false;
            layoutControlItem.Padding                 = new DevExpress.XtraLayout.Utils.Padding(0);
            layoutControlItem.ShowInCustomizationForm = false;

            LayoutControl.Refresh();
            LayoutControl.SetDefaultLayout();
        }