ProGuide Configurations - kataya/arcgis-pro-sdk GitHub Wiki
Language: C#
Subject: Framework
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, http://www.esri.com
Date: 11/24/2020
ArcGIS Pro: 2.7
Visual Studio: 2017, 2019
An ArcGIS Pro Managed Configuration is an advanced customization pattern for the application. Configurations are similar to add-ins except they have several additional opportunities to configure and extend the application. This ProGuide is split into two parts:
- Using Managed Configurations for Organizational Branding
- Using Configurations to Customize the User Interface and Functionality
Please refer to the ProConcepts: Configurations for more detailed information.
- Using Configurations for Organizational Branding
- Using Configurations to Customize the User Interface and Functionality
In order to demonstrate organizational branding we create a new Configuration using the Pro SDK's Managed Configuration template. Organizational branding in the context of Managed Configurations means that I can customize user interface elements like application icons, splash screen, startup screen, and about page to reflect my organization's brand. This section demonstrates how to customize these UI elements.
Note: The process to create a new project has changed in Visual Studio 2019. This guide shows the steps to create a new project using Visual Studio 2017. To create a new project using Visual Studio 2019, refer to this link: Create new project using Visual Studio 2019
Open Visual Studio, select File | New | Project, drill down to Installed | Templates | Visual C# | ArcGIS | ArcGIS Pro Add-ins | ArcGIS Pro Managed Configuration. Name the solution "MyConfiguration".
In Visual Studio build the project and open the properties page of the MyConfiguration project, select the Debug tab. Note that the ArcGISPro.exe is run using the /config:{configuration name}
ArcGIS Pro command line parameter.
The Managed Configuration template adds the correct command line parameter to your project automatically. When the project is built, a configuration package with a .ProConfigX file extension is installed to the default location for configurations: C:\Users\<Username>\Documents\ArcGIS\AddIns\ArcGISPro\Configurations
.
Note: If you change the name of your configuration in the project you must also change the name of the configuration in the command line switch on the Debug tab.
To debug, set breakpoints as normal and click 'start' to run the configuration (ensuring your active Visual Studio configuration is Active (Debug)
).
Open "ConfigurationManager1.cs". Scroll to the OnShowSplashScreen
override method. The Managed Configurations template will have added a default implementation of a splash screen window for you in "SplashScreen.xaml" that you can customize (or delete the callback or return null to retain the stock splash screen).
Open "ConfigurationManager1.cs". Scroll to the OnShowStartPage
override method. The Managed Configurations template adds a default implementation of a startup page for you in "StartPage.xaml" that you can customize (or delete the callback or return null to retain the stock startup page). Configurations use the Model-View-ViewModel, MVVM, pattern so the startup page view also has a companion view model: "StartPageViewModel.cs". It is your responsibility to initialize the startup page datacontext with the view model for purposes of binding as shown here:
if (_vm == null)
{
_vm = new StartPageViewModel();
}
var page = new StartPage();
page.DataContext = _vm;//Initialize the datacontext
return page;
Your startup page is automatically closed when an ArcGIS Pro project file is opened. You do not have to close it:
if (dlg.ShowDialog() ?? false)
{
var item = dlg.Items.FirstOrDefault();
if (item != null)
{
Project.OpenAsync(item.Path);//Automatically closes the startup page
}
}
To see a variety of startup page implementations please refer to following community sample:
ConfigWithStartWizard community sample code
*The Open project and New project backstage tabs should also be replaced to ensure a consistent user experience. These are separate views from the start up page. Delete the existing backstage tabs via standard DAML (i.e. <deleteTab .... />
) and add custom Open and New Project tabs to your Configuration using the "ArcGIS Pro Backstage Tab" template.
Open "ConfigurationManager1.cs". Scroll to the ApplicationName
and Icon
override properties respectively. The application name becomes part of ArcGIS Pro's window title. The icon in the title bar is changed (it reverts back though when the configuration is not run) but not the icon in the Windows task bar. Both properties are optional.
The Application Icon on Startup
The Application Icon and Name with a Project Open
The Application Icon when Switching Between Apps
Note: Use the full pack URI format as shown below. Set the icon file's build action to "Resource" in your Visual Studio project:
protected override ImageSource Icon
{
get
{
return new BitmapImage(
new Uri(
@"pack://application:,,,/MyConfiguration;component/Images/favicon.ico"));
}
}
Open "ConfigurationManager1.cs". Scroll to the OnShowAboutPage
override method. Optionally override this method to return a System.Windows.FrameworkElement
(usually a User Control) that is hosted within the Pro about tab. The Managed Configurations template adds a default implementation of about page content for you in "AboutPage.xaml" that you can customize (or delete the callback to leave the stock about page unchanged).
We will use the MyConfiguration solution we created in the previous steps for Organizational Branding. A reference implementation is also provided with the following community sample:
ConfigWithMap community sample code
Open the MyConfiguration solution we built in the previous section. Click the Start button in Visual Studio to start a debug session. Note the default ArcGIS Pro Ribbon is unchanged (assuming other add-ins are not installed on your system).
Close ArcGIS Pro and stop debugging.
Note: To examine the complete DAML for each session of ArcGIS Pro add the following command line option /dumpcombineddaml
to ArcGISPro.exe:
ArcGISPro.exe /config:MyConfiguration /dumpcombineddaml
Open "ConfigurationManager1.cs". Within ConfigurationManager1, add an override for the OnUpdateDatabase
method:
#region Override DAML Database
protected override void OnUpdateDatabase(XDocument database)
{
}
#endregion
Notice that OnUpdateDatabase
override method takes a single parameter XDocument database
. During startup, all of the DAML files from Pro (bin\Extensions), detected add-ins, and the configuration, are merged into a single DAML database (i.e. XML) (this database can be examined using the previously mentioned /dumpcombineddaml
command line option). We are going to add code in our OnUpdateDatabase
callback to remove all the tab elements on the Ribbon. Use extreme caution when editing this XML in your configurations. It defines the entire application UI.
The code snippet below collects all the tab elements from the XML database into a HashSet and then removes them. Insert this snippet into your OnUpdateDatabase override method.
protected override void OnUpdateDatabase(XDocument database) {
var nsp = database.Root.Name.Namespace;
// select all elements that are tabs
var tabElements = from seg in database.Root.Descendants(nsp + "tab") select seg;
// collect all elements that need to be removed
var elements = new HashSet<XElement>();
foreach (var tabElement in tabElements)
{
// skip root and backstage elements
if (tabElement.Parent == null
|| tabElement.Parent.Name.LocalName.StartsWith("backstage"))
continue;
var id = tabElement.Attribute("id");
if (id == null) continue;
elements.Add(tabElement);
}
// remove the elements
foreach (var element in elements)
{
element.Remove();
}
}
Run the application from Visual Studio. From your custom start page open a project or create a new project (using Map.aptx). Note that the ArcGIS Pro Ribbon is empty.
Close ArcGIS Pro.
We are going to add some custom controls and tabs to the Pro UI. Right click on the MyConfiguration project and select Add | New Item from the project context menu. Add an ArcGIS Pro Button to the configuration (select Visual C# Items | ArcGIS | ArcGIS Pro Add-ins | ArcGIS Pro Button). Name the button "TestUserInterface".
Open the newly added "TestUserInterface.cs" file. Add a MessageBox.Show("test");
line to its OnClick method.
Edit the project's "Config.daml" file. Add a new tab to the Config.daml. Ensure it contains a reference to the MyConfiguration_Group1
group:
<tabs>
<tab id="MyConfiguration_Tab1" caption="Test UI Tab" keytip="Z0">
<group refID="MyConfiguration_Group1"/>
</tab>
</tabs>
Change appearsOnAddInTab="true"
to appearsOnAddInTab="false"
on the <group ...>
element. We do not want to show the Add-ins tab on the Ribbon:
<groups>
<group id="MyConfiguration_Group1" caption="Group 1" appearsOnAddInTab="false" keytip="Z1">
<button refID="MyConfiguration_TestUserInterface" size="large" />
</group>
</groups>
Exclude our newly added tab from our removal code in our OnUpdateDatabase
override. Replace the existing if (id == null) continue;
check with if (id == null || id.Value.StartsWith("MyConfiguration")) continue;
to skip our own tab element.
Before:
protected override void OnUpdateDatabase(XDocument database)
{
...
foreach (var tabElement in tabElements)
{
...
if (id == null) continue;
After:
protected override void OnUpdateDatabase(XDocument database)
{
...
foreach (var tabElement in tabElements)
{
...
if (id == null || id.Value.StartsWith("MyConfiguration")) continue;//Skip our tabs
Save your changes and Build the project. Run the application from Visual Studio. Open a project. Verify that you see your "Test UI Tab" displayed on the Ribbon. Click the TestUserInterface button. Your message box should be displayed.
We have now changed the ArcGIS Pro user interface and functionality using a Managed Configuration. You can download the complete sample from ConfigWithMap community sample code