需要帮助将导航页面链接到导航栏(Windows Forms / DevExpress)

时间:2018-07-31 21:55:32

标签: c# winforms devexpress

我正在完成以下教程:

https://documentation.devexpress.com/WindowsForms/116628/Build-an-Application/Choose-Application-UI/Office-Inspired-UI/How-to-Build-an-Office-inspired-UI-manually

我已经在步骤8达到了期望的输出(链接办公室导航栏和导航栏控件),但是在步骤10却无法实现期望的输出(更改导航页面以显示不同的标签,具体取决于选定的导航栏组)。

这是我的Form1.Designer.cs:

namespace dev_express_again
    {
        partial class Form1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region Windows Form Designer generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.navigationFrame1 = new DevExpress.XtraBars.Navigation.NavigationFrame();
                this.navigationPage1 = new DevExpress.XtraBars.Navigation.NavigationPage();
                this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
                this.navigationPage2 = new DevExpress.XtraBars.Navigation.NavigationPage();
                this.labelControl2 = new DevExpress.XtraEditors.LabelControl();
                this.navBarControl1 = new DevExpress.XtraNavBar.NavBarControl();
                this.navBarGroup1 = new DevExpress.XtraNavBar.NavBarGroup();
                this.navBarGroup2 = new DevExpress.XtraNavBar.NavBarGroup();
                this.officeNavigationBar1 = new DevExpress.XtraBars.Navigation.OfficeNavigationBar();
                ((System.ComponentModel.ISupportInitialize)(this.navigationFrame1)).BeginInit();
                this.navigationFrame1.SuspendLayout();
                this.navigationPage1.SuspendLayout();
                this.navigationPage2.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.navBarControl1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.officeNavigationBar1)).BeginInit();
                this.SuspendLayout();
                // 
                // navigationFrame1
                // 
                this.navigationFrame1.Controls.Add(this.navigationPage1);
                this.navigationFrame1.Controls.Add(this.navigationPage2);
                this.navigationFrame1.Location = new System.Drawing.Point(146, 0);
                this.navigationFrame1.Name = "navigationFrame1";
                this.navigationFrame1.Pages.AddRange(new DevExpress.XtraBars.Navigation.NavigationPageBase[] {
                this.navigationPage1,
                this.navigationPage2});
                this.navigationFrame1.SelectedPage = this.navigationPage1;
                this.navigationFrame1.Size = new System.Drawing.Size(462, 311);
                this.navigationFrame1.TabIndex = 0;
                this.navigationFrame1.Text = "navigationFrame1";
                // 
                // navigationPage1
                // 
                this.navigationPage1.Caption = "navigationPage1";
                this.navigationPage1.Controls.Add(this.labelControl1);
                this.navigationPage1.Name = "navigationPage1";
                this.navigationPage1.Size = new System.Drawing.Size(462, 311);
                this.navigationPage1.Tag = "Employees";
                // 
                // labelControl1
                // 
                this.labelControl1.Location = new System.Drawing.Point(190, 145);
                this.labelControl1.Name = "labelControl1";
                this.labelControl1.Size = new System.Drawing.Size(33, 13);
                this.labelControl1.TabIndex = 0;
                this.labelControl1.Text = "Page 1";
                // 
                // navigationPage2
                // 
                this.navigationPage2.Caption = "navigationPage2";
                this.navigationPage2.Controls.Add(this.labelControl2);
                this.navigationPage2.Name = "navigationPage2";
                this.navigationPage2.Size = new System.Drawing.Size(462, 311);
                this.navigationPage2.Tag = "Customers";
                // 
                // labelControl2
                // 
                this.labelControl2.Location = new System.Drawing.Point(194, 135);
                this.labelControl2.Name = "labelControl2";
                this.labelControl2.Size = new System.Drawing.Size(33, 13);
                this.labelControl2.TabIndex = 0;
                this.labelControl2.Text = "Page 2";
                // 
                // navBarControl1
                // 
                this.navBarControl1.ActiveGroup = this.navBarGroup1;
                this.navBarControl1.Groups.AddRange(new DevExpress.XtraNavBar.NavBarGroup[] {
                this.navBarGroup1,
                this.navBarGroup2});
                this.navBarControl1.Location = new System.Drawing.Point(0, 0);
                this.navBarControl1.Name = "navBarControl1";
                this.navBarControl1.OptionsNavPane.ExpandedWidth = 140;
                this.navBarControl1.PaintStyleKind = DevExpress.XtraNavBar.NavBarViewKind.NavigationPane;
                this.navBarControl1.Size = new System.Drawing.Size(140, 311);
                this.navBarControl1.TabIndex = 1;
                this.navBarControl1.Text = "navBarControl1";
                // 
                // navBarGroup1
                // 
                this.navBarGroup1.Caption = "Employees";
                this.navBarGroup1.Expanded = true;
                this.navBarGroup1.Name = "navBarGroup1";
                // 
                // navBarGroup2
                // 
                this.navBarGroup2.Caption = "Customers";
                this.navBarGroup2.Name = "navBarGroup2";
                // 
                // officeNavigationBar1
                // 
                this.officeNavigationBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
                this.officeNavigationBar1.Location = new System.Drawing.Point(0, 317);
                this.officeNavigationBar1.Name = "officeNavigationBar1";
                this.officeNavigationBar1.NavigationClient = this.navBarControl1;
                this.officeNavigationBar1.Size = new System.Drawing.Size(608, 45);
                this.officeNavigationBar1.TabIndex = 2;
                this.officeNavigationBar1.Text = "officeNavigationBar1";
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(608, 362);
                this.Controls.Add(this.officeNavigationBar1);
                this.Controls.Add(this.navBarControl1);
                this.Controls.Add(this.navigationFrame1);
                this.Name = "Form1";
                this.Text = "Form1";
                ((System.ComponentModel.ISupportInitialize)(this.navigationFrame1)).EndInit();
                this.navigationFrame1.ResumeLayout(false);
                this.navigationPage1.ResumeLayout(false);
                this.navigationPage1.PerformLayout();
                this.navigationPage2.ResumeLayout(false);
                this.navigationPage2.PerformLayout();
                ((System.ComponentModel.ISupportInitialize)(this.navBarControl1)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.officeNavigationBar1)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();

            }

            #endregion

            private DevExpress.XtraBars.Navigation.NavigationFrame navigationFrame1;
            private DevExpress.XtraBars.Navigation.NavigationPage navigationPage1;
            private DevExpress.XtraBars.Navigation.NavigationPage navigationPage2;
            private DevExpress.XtraNavBar.NavBarControl navBarControl1;
            private DevExpress.XtraNavBar.NavBarGroup navBarGroup1;
            private DevExpress.XtraNavBar.NavBarGroup navBarGroup2;
            private DevExpress.XtraBars.Navigation.OfficeNavigationBar officeNavigationBar1;
            private DevExpress.XtraEditors.LabelControl labelControl1;
            private DevExpress.XtraEditors.LabelControl labelControl2;
        }
    }

还有我的Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dev_express_again
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            navigationPage1.Tag = navBarGroup1.Caption = navigationPage1.Caption = "Employees";
            navigationPage2.Tag = navBarGroup2.Caption = navigationPage2.Caption = "Customers";

            officeNavigationBar1.NavigationClient = navBarControl1;
        }

        private void navBarControl1_ActiveGroupChanged(object sender, DevExpress.XtraNavBar.NavBarGroupEventArgs e)
        {
            navigationFrame1.SelectedPage = (DevExpress.XtraBars.Navigation.NavigationPage)navigationFrame1.Pages.FindFirst(x => (string)x.Tag == e.Group.Caption);
        }
    }
}

据我所知,两者都与本教程完全相同。运行代码时,我会看到一个窗口,该窗口与本教程中的窗口完全相同。当我在办公室导航栏中更改选择时,它会反映在导航栏控件中,但不会更改导航页面。

关于我想念的东西有什么想法吗?

1 个答案:

答案 0 :(得分:0)

找出解决方案。忽略了该教程,您还必须在Form1.cs中添加行navBarControl1.ActiveGroupChanged += new DevExpress.XtraNavBar.NavBarGroupEventHandler(navBarControl1_ActiveGroupChanged);,以使用户更改活动组可以实际调用navBarControl1_ActiveGroupChanged函数。