[SOLVED] MVVM - OnPropertyChanged problem - Setter not set

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
ThibTib
Posts: 16
Joined: Tue May 31, 2016 10:34 am

[SOLVED] MVVM - OnPropertyChanged problem - Setter not set

Postby ThibTib » Mon Aug 29, 2016 12:18 pm

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.
Last edited by ThibTib on Thu Sep 01, 2016 4:13 am, edited 1 time in total.
--
ThibTib

ThibTib
Posts: 16
Joined: Tue May 31, 2016 10:34 am

Re: MVVM - OnPropertyChanged problem - Setter not set

Postby ThibTib » Thu Sep 01, 2016 3:49 am

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 ?
--
ThibTib

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: MVVM - OnPropertyChanged problem - Setter not set

Postby JS-Support @Userware » Thu Sep 01, 2016 3:52 am

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

ThibTib
Posts: 16
Joined: Tue May 31, 2016 10:34 am

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

Postby ThibTib » Thu Sep 01, 2016 4:21 am

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.
--
ThibTib


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 39 guests

 

 

cron