前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【ArcGIS Pro SDK for Microsoft .NET基础-2】开发实现登录页面

【ArcGIS Pro SDK for Microsoft .NET基础-2】开发实现登录页面

作者头像
X北辰北
发布2022-02-21 16:54:04
8280
发布2022-02-21 16:54:04
举报
文章被收录于专栏:ArcGIS JS API开发ArcGIS JS API开发

这个系列我们介绍一下ArcGIS Pro SDK for Microsoft .NET的开发,本文是此系列的第二篇文章,我们在上一节创建的demo基础上,来增加一个登录页面。

写在前面

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

操作步骤

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

img
img

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

img
img

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

img
img

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

img
img
img
img

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

img
img
代码语言:javascript
复制
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文件,打开此页面的设计器面板,这个面板默认会展示我们的项目名称,我们在这里将展示的文字修改成我们系统的名称,如下:

img
img
img
img

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

img
img
代码语言:javascript
复制
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系统界面,如下所示:

img
img
img
img
img
img

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-11-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 写在前面
  • 操作步骤
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档