Confusing - MVVM WPF and Commands

1489
2
Jump to solution
10-31-2019 08:12 AM
Vidar
by
Occasional Contributor II

Sorry, I'm getting totally confused with WPF and how it works with MVVM and ESRI's SDK. I need to know where the most helpul, most appropriate resources are for this kind of development.

At the moment I'm getting hung up over Commands and ArcGIS.Desktop.Framework.Controls.ProWindow.  It's just a simple user login interface and trying to figure out how the Login button should activate/light up.  Obviously I want to enable it when the user enters a username and password - but it's so confusing when you try to implement a command -

  1. Should I just use simple code behind?
  2. Should I build out an elaborate MVVM solution of my own making?
  3. Should I use Prism or ActiPro or some other 3rd Party library?

When you start binding objects its hard to know which way you should bind, do you do it all in the XAML or all in code or a bit of both, what is the right way? There is no obvious way despite looking at tons of different tutorials and videos on the subject. Everyone has a slightly different way of doing things.

Main Question

How do you pass a binded object for evaluation through the command implementation? That is, the object is a "User" which is the Model (wrapped up in the ViewModel class) and has properties or Username, Password, PortalUrl - the UserViewModel comprises the User object and exposes it's inner properties of the User object so it can bind - but then I find it confusing trying to use a Command to check the object to see if its valid (i.e. completed out username/password/portalurl).

Maybe I am over complicating things for something this simple, but on the other hand I want to do things the right way and not just hack something together. In the end I will be putting together a more complex UI and I will need to know this stuff in any case so I may as well learn it now with something simple.

If anyone can help put me on the right track I would appreciate it.

Tags (2)
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Simon,

Pro implements its own MVVM framework.  You can see this when you use Pro SDK templates such as Dockpane. The dockpane item template (available using the Pro SDK in Visual Studio) stubs out the View (XAML user control and code behind file) with the View Model class file.  You can also check out the various samples in the arcgis-pro-sdk-community-samples repo for examples of Pro's implementation of MVVM.

For your specific scenario, you set the Datacontext of your ProWindow to the "ViewModel" class file. This view model should inherit from ArcGIS.Desktop,Framework.Contracts.PropertyChangedBase base class. I made a simple mockup of a login prowindow sample.  Attached.

Thanks

Uma

View solution in original post

2 Replies
UmaHarano
Esri Regular Contributor

Hi Simon,

Pro implements its own MVVM framework.  You can see this when you use Pro SDK templates such as Dockpane. The dockpane item template (available using the Pro SDK in Visual Studio) stubs out the View (XAML user control and code behind file) with the View Model class file.  You can also check out the various samples in the arcgis-pro-sdk-community-samples repo for examples of Pro's implementation of MVVM.

For your specific scenario, you set the Datacontext of your ProWindow to the "ViewModel" class file. This view model should inherit from ArcGIS.Desktop,Framework.Contracts.PropertyChangedBase base class. I made a simple mockup of a login prowindow sample.  Attached.

Thanks

Uma

Vidar
by
Occasional Contributor II

Hi Uma,

Many thanks - that's super helpful, simple I know, but I done some things the same as what you have done and some other things I didn't know about (e.g. a RelayCommand already exists to make use of). Really appreciated!!

0 Kudos