Select to view content in your preferred language

Access one Page ViewModel from another Page ViewModel

3995
3
Jump to solution
10-22-2019 06:53 AM
DavidLaMartina
Regular Contributor

To avoid creating another complex object within our Add-In's primary Module class, we'd like to have some our Page View Models (used in our custom Options pages) access one another. Is there any kind of built-in or best practice way of doing this?

Given the singleton nature of Dockpanes, it seems like this would be possible in that context (something like a call to FrameworkApplication.DockPaneManager.Find(_dockPaneID within another dock pane), where _dockPaneID is known, and we cast the result to whatever specific DockPane subclass we need.

Similarly, there's the "Current" scheme used with Modules, which just returns the result of a call to FindModule(_moduleID).

Is there something analogous to be done with Pages? If not, has anyone achieved something similar using a different scheme? Ultimately, we just need various options Pages to know about each other's changed properties, which represent the settings of our Add-In.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DavidLaMartina
Regular Contributor

Thanks! We ended up doing something similar by calling PropertySheet.Page(_pageID) from various Page view models that needed to access one another. Along with some logic to ensure certain view models were already initialized and subscribed to certain events, it's working as needed.   

View solution in original post

0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi David,

That question is more about wpf developing then ArcGIS Pro API. If you use some framework (Prism or etc.) for developing wpf application so can check your framework for solution you need. If you use plane wpf as I do then you can use messaging:

https://stackoverflow.com/questions/23798425/wpf-mvvm-communication-between-view-model

I use it in my projects to communicate between pages, pages and parent of pages and etc.

0 Kudos
UmaHarano
Esri Regular Contributor

There are a few samples in the arcgis-pro-sdk-community-samples repo where view models can be accessed from other user controls or other class files.

Code snippet similar to this is used in MagnifierWindow sample:

 internal MapControlWindow_ViewModel viewModel = null; //member variable

 viewModel = new MapControlWindow_ViewModel();
 //Now you can access the public methods and properties in the viewmodel like this
viewModel .UpdateMapControlContent();

Code snippet in MetadataBrowserControl sample:

//The viewmodel
MetadataBrowserViewModel vm = FrameworkApplication.DockPaneManager.Find("MetadataBrowserControl_Dockpane1") as MetadataBrowserViewModel;
...
vm.DockpaneVisible = System.Windows.Visibility.Visible; //Visibility is set‍‍‍‍‍‍

Thanks

Uma

DavidLaMartina
Regular Contributor

Thanks! We ended up doing something similar by calling PropertySheet.Page(_pageID) from various Page view models that needed to access one another. Along with some logic to ensure certain view models were already initialized and subscribed to certain events, it's working as needed.   

0 Kudos