I created a check box and a combo box in a ProWindow. In the xaml file, this is defined as follows:
<CheckBox x:Name="checkBoxSchool" IsChecked="{Binding SchoolChecked}" Content="School"/>
<ComboBox x:Name="comboBoxSchool" ItemsSource="{Binding SchoolItems}" SelectedItem="{Binding SelectedSchoolItem}" IsEnabled="{Binding SchoolComboEnabled}"/>
When the ProWindow is opened, the check box should be disabled. The code in the view model is:
private void InitViewModel()
{
SchoolComboEnabled = false;
}
public bool SchoolComboEnabled
{
get { return _schoolComboEnabled; }
set
{
_schoolComboEnabled = value;
OnPropertyChanged();
}
}
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
This works.
When the user checks the check box, the combo box should become enabled:
public bool SchoolChecked
{
get { return _schoolChecked; }
set
{
_schoolChecked= value;
if (_schoolChecked)
{
SchoolComboEnabled = true;
OnPropertyChanged();
}
}
}
This doesn't work, i.e. the check box doesn't become enabled.
I tried the exact same code in a dock pane, and it worked! The problem is that I need a window and not a dock pane.
I also created a user control that is embedded in a ProWindow (see ReusableUserControl ) but this doesn't work neither.
Any help is appreciated!
Solved! Go to Solution.
I found out what I missed: I have to specify that my view model class implements the interface INotifyPropertyChanged:
public class WindowEducationPointsViewModel : INotifyPropertyChanged
PropertyChangedBase is a convenience base class that implements INotifyPropertyChanged. It's the same base class that is also used by DockPane and Pane (you have to follow the inheritance of these classes to find PropertyChangedBase). If you derive your ProWindowViewModel class from PropertyChangedBase like this:
public class ProWindowDialogVM : PropertyChangedBase
You can now take advantage of convenience methods in PropertyChangedBase that implement INotifyPropertyChanged. For example, i can implement a public property called UserName like this:
private string _userName;
public string UserName
{
get { return _userName; }
set
{
SetProperty(ref _userName, value, () => UserName);
}
}
SetProperty is implemented by PropertyChangedBase which in turn implements INotifyPropertyChanged. So if I use this snippet to set the UserName property:
UserName = "My Name";
the SetProperty method will automatically raise the required property changed notification. I can also raise a notification changed event manually by calling:
NotifyPropertyChanged(() => UserName);
You will find SetProperty and NotifyPropertyChanged throughout our samples, that's the reason why the view model in the sample above derives from PropertyChangedBase.
I found out what I missed: I have to specify that my view model class implements the interface INotifyPropertyChanged:
public class WindowEducationPointsViewModel : INotifyPropertyChanged
There is a ProWindow sample that supports MVVM: arcgis-pro-sdk-community-samples/Framework/ProWindowMVVM at master · Esri/arcgis-pro-sdk-community-s...
Thank you Wolf. In the sample you mention, the view model class inherits from PropertyChangedBase:
public class ProWindowDialogVM : PropertyChangedBase
However, in order to change the enabled or checked property of a GUI component programmatically, the view model class has to implement INotifyPropertyChanged.
PropertyChangedBase is a convenience base class that implements INotifyPropertyChanged. It's the same base class that is also used by DockPane and Pane (you have to follow the inheritance of these classes to find PropertyChangedBase). If you derive your ProWindowViewModel class from PropertyChangedBase like this:
public class ProWindowDialogVM : PropertyChangedBase
You can now take advantage of convenience methods in PropertyChangedBase that implement INotifyPropertyChanged. For example, i can implement a public property called UserName like this:
private string _userName;
public string UserName
{
get { return _userName; }
set
{
SetProperty(ref _userName, value, () => UserName);
}
}
SetProperty is implemented by PropertyChangedBase which in turn implements INotifyPropertyChanged. So if I use this snippet to set the UserName property:
UserName = "My Name";
the SetProperty method will automatically raise the required property changed notification. I can also raise a notification changed event manually by calling:
NotifyPropertyChanged(() => UserName);
You will find SetProperty and NotifyPropertyChanged throughout our samples, that's the reason why the view model in the sample above derives from PropertyChangedBase.