Page 1 of 1

[SOLVED] MVVM - OnPropertyChanged problem - Setter not set

Posted: Mon Aug 29, 2016 12:18 pm
by ThibTib
Hi,
my problem is in my MVVM system.
I have a XAML view and a ViewModel.
When I change the value of my ComboBox, the setter of the property of the selected value of the combobox is not set (ie the debugger do not pass in it), and so the NotifyPropertyChanged is not raised, and so my view is not refreshed.
Here is some code :

The view :

Code: Select all

...
<ComboBox Grid.Row="1" ItemsSource="{Binding ListOfCategories}" DisplayMemberPath="Libelle" SelectedValuePath="Code" SelectedValue="{Binding SelectedCategorie, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsCategorieEnabled, Mode=TwoWay}" />
...


the code-behind of the view :

Code: Select all

public partial class AskTextQuestionPage : Page
    {
        public AskTextQuestionPage()
        {
            InitializeComponent();
            DataContext = new AskTextQuestionViewModel();
        }
    }


The ViewModel (the list is filled in the constructor of the class):

Code: Select all

class AskTextQuestionViewModel : ViewModelBase
{
...
private ObservableCollection<Categorie> _listOfCategories;
public ObservableCollection<Categorie> ListOfCategories
        {
            get
            {
                return _listOfCategories;
            }
            set
            {
                _listOfCategories = value;
            }
        }
       
        public string SelectedCategorie
        {
            get
            {
                return _selectedCategorie;
            }
            set
            {
                _selectedCategorie = value;
                NotifyPropertyChanged();
            }
        }




The ViewModelBase class :

Code: Select all

public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }


I think in pure XAML (I mean in a pure WPF app) it should work (not tested :s, it's the next step...), so should the problem come from the implementation of INotifyPropertyChanged in the beta ?

Thx for your reply.
ThibTib.

Re: MVVM - OnPropertyChanged problem - Setter not set

Posted: Thu Sep 01, 2016 3:49 am
by ThibTib
So I tested it in a WPF app : it works well, when I change the comboBox value, the debugger comes in the setter of the SelectedValue.

Does it exist some specific tips to use INotifyPropertyChanged in a CSHTML5 app, or do I have to dig deeply in my implementation of it ?

Re: MVVM - OnPropertyChanged problem - Setter not set

Posted: Thu Sep 01, 2016 3:52 am
by JS-Support @Userware
Hi,

We are going to try to reproduce the issue.

Did you test with the latest Beta 9.1, which completely revamped the ComboBox implementation?

Thanks.
Regards,
JS-Support

Re: [SOLVED] MVVM - OnPropertyChanged problem - Setter not set

Posted: Thu Sep 01, 2016 4:21 am
by ThibTib
Here is what was missing in my XAML :

Code: Select all

<ComboBox Grid.Row="1" ItemsSource="{Binding ListOfCategories}" DisplayMemberPath="Libelle" SelectedValuePath="Code" SelectedValue="{Binding SelectedCategorie, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />


The UpdateSourceTrigger and the Mode have to be set to these values.
In WPF, the solution works without them.