wpftoolkit icon indicating copy to clipboard operation
wpftoolkit copied to clipboard

PropertyGrid property value in nested structs not updating

Open DanielSchafer87 opened this issue 4 years ago • 4 comments

Xceed.WPF.Toolkit version 4.1.0

Little background, I'm working on a WPF desktop application that displays structs from a DLL and the user is able to change properties in those structs and send the updated struct.

I'm facing an issue when trying to change a property in a nested struct from 3rd degree, for example:

A_Struct →                 ↓                 B_Struct →                                 ↓                                 C_Struct

So when trying to change a property in C_Struct (for example C_Struct.X_Prop) I see the change in the UI and I also see that the PropertyGrid_PropertyValueChanged is triggered. but when I'm tying to use the selected object:

SelectedObject="{Binding CommandData}"

In CommandData I do not see the change that was just made in C_Struct.X_Prop, instead I still see the original value.

The workaround that i found for this issue it to first change C_Struct.X_Prop and after that change other property in B_Struct.Y_Prop and only after that i see the desired change of C_Struct.X_Prop in CommandData.

Note: when changing a property in B_Struct or A_Struct i see the change CommandData with no problem.

Code: XAML: <xctk:PropertyGrid Grid.Row="1" SelectedObject="{Binding CommandData}" />

View Model:

  public object _commandData;

  public object CommandData
  {
      get
      {
          return _commandData;
      }
      set
      {
          _commandData = value;
          RaisePropertyChanged();
      }
  }

SelectedCommand.Command.Payload = CommandData;

DanielSchafer87 avatar Jul 20 '21 07:07 DanielSchafer87

Hi, Could you attached a complete sample so we could have the exact same sample as you to test ? Thank you.

XceedBoucherS avatar Aug 10 '21 18:08 XceedBoucherS

@XceedBoucherS Example Attached: WPFExample.zip

Short explanation, try to change first only RTC_Hours and click "Print Struct" you will see that RTC_Hours is not updated. After that first change RTC_Hours and then change CounterType, now when you click "Print Struct" you will see the both properties updated. image

DanielSchafer87 avatar Aug 12 '21 06:08 DanielSchafer87

Hi, thank you for the sample. The issue has been identified and will be fixed in v4.3.

In the meantime, you can go in file Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.cs, In method PropertyGrid_PropertyValueChanged and replace if( ( parentPropertyItem != null ) && parentPropertyItem.IsExpandable ) { this.RebuildPropertyItemEditor( parentPropertyItem ); } with: `while( ( parentPropertyItem != null ) && parentPropertyItem.IsExpandable ) { this.RebuildPropertyItemEditor( parentPropertyItem );

      parentPropertyItem = parentPropertyItem.ParentNode as PropertyItem;
    }`

Thank you.

XceedBoucherS avatar Aug 12 '21 13:08 XceedBoucherS

Thanks!

DanielSchafer87 avatar Aug 15 '21 04:08 DanielSchafer87