Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
NotifyPropertyChanged ignored by NumericEditor
posted

I have a XamDataGrid where one column is an UnboundField bound to a value from an array, it is setup to edit as a decimal value, most of the setup is:

 

field.DataType = typeof(object);

field.BindingPath = new PropertyPath("Cells[" + index + "].Value");

field.Settings.CellValuePresenterStyle = Global.Instance.Cache.GetCellValuePresenterStyle(index);

field.Settings.EditAsType = typeof(decimal);

field.Settings.SortComparer = new DecimalSorter();

string numberFormat = "-nnn,nnn,nnn,nnn,nnn";

if (_precision > 0)

numberFormat += "." + new string('n', _precision);

Style editStyle = new Style(typeof(XamNumericEditor));

editStyle.Setters.Add(new Setter(XamNumericEditor.MaskProperty, numberFormat));

field.Settings.EditorType = typeof(XamNumericEditor);

field.Settings.EditorStyle = editStyle;

field.Converter = new DecimalConverter();

 

 

Normally I can change the value that the cell is bound to and call NotifyPropertyChanged("Value") on the object and it updates everything just fine, the problem comes when I have just edited a value in a cell by typing in a new number and hitting enter, then some external UI changes the value that should be held in that cell. Every other cell in the grid updates fine, but the one I was just editing ignores the NotifyPropertyChanged and doesn't update at all, if you scroll that row off the screen and then back again it will then display the new value correctly.

It seems like because that cell was just being edited the NumericEditor is storing a value and not getting notified of the NotifyPropertyChanged call, how can I force the cell to update without telling the user to scroll down and then back up again?

Parents
  • 260
    Suggested Answer
    Offline posted

    I was able to come up with the following workaround, before I was doing:

    if (needRefresh[columnNumb])

        currentIntervalBinder.CallNotifyValueChanged(columnNumb);

    Which called NotifyPropertyChanged("Value") on what that column is bound to for every cell, this worked UNLESS you were just editing a cell, in which case it ignored the change in value until you scrolled that row off the screen and back again.

    My workaround is to manually set the CellValuePresenter value by doing:

    if (needRefresh[columnNumb])

    {

    foreach (DataRecord record in DataGrid.Records)

    {

    CellValuePresenter present = CellValuePresenter.FromRecordAndField(record, DataGrid.FieldLayouts[0].Fields[columnNumb]);

     

    if (present != null && present.Editor != null)

    {

    object value = ((RowData)record.DataItem).Cells[columnNumb].Value;

     

    if (!value.Equals(present.Value))

    present.Value = value;

    }

    }

    }

Reply Children
No Data