There is a view of the model wpf page. It indicates the property:

string totalST; public string totalStproperty { get { return totalST; } set { totalST = value; } } 

In the class constructor, the value is passed to the property for the first time:

 totalST = "Всего студентов " + allS.Rows.Count.ToString(); 

And in the markup, the property is bound to:

  <Label x:Name="allStudents" Content="{Binding totalStproperty, Mode=TwoWay}"/> 

At the first page load, the total number of students will be shown, equal to the rows in the corresponding table. But then we call a command that shows only a part of the students in the table - accordingly, the number in the label should also change:

 public RelayCommand<ListBoxItem> SelectFilter { get { return new RelayCommand<ListBoxItem>(DataGridRefresh); } } private void DataGridRefresh(ListBoxItem selected) { totalST= "Всего студентов 0"; } 

It does not show errors, it is compiled, but it is executed incorrectly. totalST takes the value of "Всего студентов 0" but the old value in the Label hangs as if there was no Binding . Where is the mistake?

    1 answer 1

    In the set access method of the RaisePropertyChanged(() => ваше свойство) method must be called in order for the interface to be notified that the property value has changed.

     public string totalStproperty { get { return totalST; } set { totalST = value; RaisePropertyChanged(() => totalStproperty); } } 
    • The method call cannot be there. because the ListBoxItem property of the Content being passed to the called method, which serves as a parameter for the method that returns a new table and, therefore, does not get the number of rows. or something I do not understand? - Sergey
    • What does the ведь в вызываемый метод передается ListBoxItem ? You have a totalStproperty property that is tied to the Label.Content property. This means that any change in the value of the totalStproperty property will affect the value of the Label.Content property (exactly the opposite, because the TwoWay binding). But you do not have this happening. Why? And this does not happen because, as I wrote in the answer, that the interface does not receive notifications about the change in the value of the totalStproperty property (the property itself has changed, but the interface does not know about it, therefore it does not automatically update the data). - sp7
    • To make everything work, you need to tell the interface that the totalStproperty property has been totalStproperty by calling the RaisePropertyChanged(() => ваше свойство) method in the set accessor. - sp7
    • Error - Ни одна из перегрузок метода "RaisePropertyChanged" не принимает 1 аргументов - Sergey
    • set {totalST = value; RaisePropertyChanged (() => totalStproperty); } - Sergey