How to populate Textboxes with values from settings file in backstage tab

1095
8
11-06-2019 01:33 AM
TomGeo
by
Occasional Contributor III

I am trying to provide my users with the possibility to adjust values that I by default set in a settings file of my addin through a backstage tab. I designed the UI in the tab to resample the tab design of ArcGIS Pro  (link to my question about the UI) and have now a ArcGIS Pro Pane on the right hand where I put some textboxes.

When initializing the backstage tab the settings file should be read and the textboxes populated with the respective values.


Here I have my first question, since the ArcGIS Pro Pane comes with its own view model... do I have to put the code there or is it absolutely fine to put the code into the code behind file?
My other question is about how to get the retrieved values into the textboxes. Currently I have a public property in the view model and I can see the xaml file is aware of the property bound to it, but I have no clue about where to put the code to retrieve the value from the settings file.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
Tags (2)
0 Kudos
8 Replies
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

What do you mean "settings file"? ArcGIS Pro project settings or your own  custom settings file? If it is ArcGIS Pro project settings then you need to follow example on GitHub from ArcGIS Pro. Else you need to  and read settings file and set your setting parameters to corresponding page properties binded to xaml controls. All properties must be public.

All code stuff you need to put in to:

protected override Task InitializeAsync()

{

}

0 Kudos
TomGeo
by
Occasional Contributor III

Hi Gintautas,

yes, I have my own custom settings file.
I think I am running loops here... The backstage tab has its view model and the respective xaml file is setting the data context to its own view model. The same applies to the pane.

Both view models are set as internal.

What ever I do in the view model of the backstage tab has no effect on the text property. Makes sense so far, since the binding in the pane xaml file is looking into the panes view model... If I define the following in the panes view model then it doesn't have an effect either:

public static string UrlDHM;
public static void GetSettings()
    {
        UrlDHM = Appsettings.Default.urlDHM;
    }
protected async override Task InitializeAsync()
    {
        GetSettings();
        await base.InitializeAsync();
    }
- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

It is not enough for your property declaring. You need to do like that:

private string _urlDHM;

public string UrlDHM

{

get { return _urlDHM; }

set

{

 SetProperty(ref _urlDHM, value, () => UrlDHM);

 }

}

You need to notify view that something was changed in the model.

0 Kudos
TomGeo
by
Occasional Contributor III

Hi Gintautas, that's how I normally define my properties and I tried that, but also this does not reflect on the textbox text property:

private string _urlDHM;
public string UrlDHM
{
    get => _urlDHM;
    set => SetProperty(ref _urlDHM, value, ()=> UrlDHM);
}

protected async override Task InitializeAsync()
    {
        UrlDHM = AppSettings.Default.urlDHM;
        await base.InitializeAsync();
    }

In fact the breakpoint I set on line 9 is never fired.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

Could you please make a copy from xaml of texbox control.

If debugger never goes inside InitializeAsync then problem is with DataContext of your page. It does not found your view model.

Check xaml header:

d:DataContext="{Binding Path=YourPageViewModel}"

0 Kudos
TomGeo
by
Occasional Contributor III

I know it's more than a minimal example! Sorry for that!

You find the definition of the textbox in question in line 49 of the pane xaml.

backstage tab xaml: Link

backstage tab code behind: Link

backstage tab view model: Link

pane xaml: Link

pane code behind: Link

pane view model: Link

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

I have created new project and classes with  your names. StepperBackstagePane works fine for me from Add-in button.

        protected async override Task InitializeAsync()
        {
            UrlHeight = "xxx";
            await base.InitializeAsync();
        }

Check config.daml file for pane className and content className attributes. They must match your classes. I have had similar problem when I tried to rename esri sample source code.

        <pane id="Stepper_MVVM_StepperBackstagePane" caption="StepperBackstagePane" className="StepperBackstagePaneViewModel" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonGreen16.png" defaultTab="esri_mapping_homeTab" defaultTool="esri_mapping_navigateTool">
          <content className="StepperBackstagePaneView" />
        </pane>

I don't know your application architecture so I have not checked other content (FaksBackstageTabViewModel and etc.)

I have tried to go deep. From  backstage  Stepper button StepperBackstagePane does not work as you wrote. In way you create StepperBackstagePane it does not get InitializeAsync() event.

You need to create your own constructor or modify existing to read settings. Pane you created is not usable for your solution. It is designed as ArcGIS Pro Map pane or Attribute table table pane. It has own way of pane creating.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

We provide ProGuide documentation that answers the original question:  https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-Custom-settings

0 Kudos