WPF GridView غير التحديث على تغيير جمع الملاحظ

StackOverflow https://stackoverflow.com/questions/5051530

  •  15-11-2019
  •  | 
  •  

سؤال

لدي telerik radgridview ملزمة بالملاحظ من النوع المحدد .. عند تحديث قيمة خاصية معينة في هذا النوع، تتم تحديث المجموعة المرئية المقابلة ولكنها غير محدثة ولكن ليس RadgridView ..

أدناه هو XAML: giveacodicetagpre.

أدناه هو رمز النموذج الرأي: giveacodicetagpre.

فئة كائن: giveacodicetagpre.

هل كانت مفيدة؟

المحلول

Each item within the Observable Collection must have a way to signal to WPF and therefore the control that it is updating so that the Quantity Value can be updated. The Observable Collection update is occuring because that collection contains in built change notification for its collection but not its individual items. As others have said implement INotifyPropertyChanged on Result and it should work.

public class Result : INotifyPropertyChanged
{

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    protected void Notify(string propName)
    {
        if (this.PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
    #endregion


    private decimal _weight;

    public decimal Weight
    {
        get { return _weight; }
        set { 

            this._weight = value;
            Notify("Weight");
        }
    }
}

نصائح أخرى

As Erno said your Result class needs to implement INotifyPropertyChanged and you need to call OnPropertyChanged for the Weight property.

Also, your ViewModel should also implement INotifyPropertyChanged so you can avoid the casting to IHaveOnPropertyChangedMethod (that naming is pretty bad btw) that you have in your code. I would suggest having a ViewModelBase : INotifyPropertyChanged class that all your ViewModels inherit from. If you don't want to write one yourself there are plenty of MVVM frameworks out there that have this built in.

If the update that you are making is an update to the Weight property of a Result Object then this might be caused by the fact that the Result class is not inmplementing INotifyPropertyChanged.

ICollectionChanged (and thus ObservableCollection too) only notifies changes to the collection (adding and removing items).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top