欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

程序员文章站 2022-06-13 14:16:47
...

写在前面

前一篇文章介绍了ArcGIS Pro SDK for Microsoft .NET开发环境的搭建,并且在文章最后我们创建了一个demo并让它成功运行。这一篇文章我们介绍下如何在前面创建的demo基础之上增加一个登录页面。

操作步骤

1、打开上一节创建的demo代码,然后在"UI"文件夹上面鼠标右击,依次选择【添加 | 新建项】,在打开的新建项窗口选择新建一个WPF的窗口,并为其取名为"Login",如下图所示:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

2、新建Login窗口之后,我们的右侧项目代码UI目录下会出现新建的Login窗口代码文件,如下所示:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

3、鼠标双击新建的Login窗口代码文件,然后在左侧的设计窗口将【工具栏】中的Label、Button、TextBox控件拖动至Login的设计器面板,最终形成如下所示的一个窗体:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

4、然后鼠标依次点击此页面中的登录和取消两个按钮,在右下方的属性面板中给这两个分别设置名称,如下:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

 

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

5、在设计器面板分别鼠标双击登录和取消按钮,分别为这两个按钮绑定点击事件,在这里就做一些简单的操作,点击登录按钮时不进行登录校验,只需要打开后续的面板即可,点击取消按钮时就让系统退出,代码如下:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ProConfigurationdemo2.UI
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
        }

        private void login_btn_Click(object sender, RoutedEventArgs e)
        {
            //实现登录验证相关的代码
            this.DialogResult = true;
        }

        private void login_cance_btn_Click(object sender, RoutedEventArgs e)
        {
            //取消登录
            this.DialogResult = false;
        }
    }
}

6、然后在代码目录结构中双击UI目录下的SplashScreen.xaml文件,打开此页面的设计器面板,这个面板默认会展示我们的项目名称,我们在这里将展示的文字修改成我们系统的名称,如下:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

 

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

7、双击代码目录中的ConfigurationManager1.cs代码文件,然后在此代码文件中新建ConfigurationManager1构造函数,并且在构造函数中实例化我们之前新建的Login面板,这样一来,我们项目启动时会首先打开新建的登录面板,然后只有我们点击登录时才会真正进入系统,如下:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ProConfigurationdemo2.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;



namespace ProConfigurationdemo2
{
    internal class ConfigurationManager1 : ConfigurationManager
    {

        public ConfigurationManager1()
        {
            //启用login页面
            //只有在调用Application对象的Shutdown方法时,应用程序才会关闭
            System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
            Login login = new Login();
            if((bool)login.ShowDialog())
            {
                login.Close();
            }
            else
            {
                Environment.Exit(0);
            }
        }


        /// <summary>
        /// Replaces the default ArcGIS Pro application name
        /// </summary>
        protected override string ApplicationName
        {
            get { return "ProConfigurationdemo2"; }
        }

        /// <summary>
        /// Replaces the ArcGIS Pro Main window icon.
        /// </summary>
        protected override ImageSource Icon
        {
            get
            {
                return new BitmapImage(new Uri(@"pack://application:,,,/ProConfigurationdemo2;component/Images/favicon.ico"));
            }
        }

        #region Override Startup Page

        private StartPageViewModel _vm;
        /// <summary>
        /// Called before ArcGIS Pro starts up. Replaces the default Pro start-up page (Optional)
        /// </summary>
        /// <returns> Implemented UserControl with start-up page functionality. 
        /// Return null if a custom start-up page is not needed. Default ArcGIS Pro start-up page will be displayed.</returns>
        protected override System.Windows.FrameworkElement OnShowStartPage()
        {
            if (_vm == null)
            {
                _vm = new StartPageViewModel();
            }
            var page = new StartPage();
            page.DataContext = _vm;
            return page;
        }

        ///<summary>
        ///During the start up this method is called after it is safe to access Portal and use ArcGIS.Desktop.Core. 
        ///ArcGIS Pro Theme has already been set. 
        ///</summary>
        ///<param name="cancelEventArgs">
        ///To cancel initialization, set the cancelEventArgs.Cancel property to true.
        ///</param>
        protected override void OnApplicationInitializing(CancelEventArgs cancelEventArgs)
        {

        }

        ///<summary>
        ///During the start up this method is called after the Application Window Start page is ready. From here on calls to ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask are safe.
        ///ArcGIS Pro Extension modules can now be accessed. 
        ///</summary>
        protected override void OnApplicationReady()
        {

        }

        #endregion

        #region Override Splash screen
        /// <summary>
        /// Called while ArcGIS Pro starts up. Replaces the default Pro splash screen. (Optional)
        /// </summary>
        /// <returns>Implemented Window with splash screen functionality. 
        /// Return null if a custom splash screen is not needed. Default ArcGIS Pro splash screen will be displayed.</returns>
        protected override System.Windows.Window OnShowSplashScreen()
        {
            return new SplashScreen();
        }
        #endregion

        #region Override About page
        /// <summary>
        /// Customized UserControl is displayed in ArcGIS Pro About property page. Allows to add information about this specific managed configuration.
        /// </summary>
        /// <returns>Implemented UserControl with about box information. 
        /// Return null if a custom about box is not needed. Default ArcGIS Pro About box will be displayed.</returns>
        protected override System.Windows.FrameworkElement OnShowAboutPage()
        {
            return new AboutPage();
        }
        #endregion
    }
}

8、此时我们启动项目,发现系统首先进入登录面板,然后我们点击登录按钮时,才会出现之前我们创建的demo系统界面,如下所示:

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

 

 

 

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

02【ArcGIS Pro SDK for Microsoft .NET】开发实现登录页面

9、至此,我们的登陆界面定制开发完成。当然,我们在此处仅仅是介绍了如何新建一个登录页面,并将其注册为系统起始页的方法,里面的逻辑代码并没有详细的编写,大家在实际项目中自己编写登录页面的逻辑代码即可。