Properties displayed twice in the grid

Grids for WPF Forum

Posted 6 years ago by Hagay
Version: 17.2.0660
Avatar

Hi all,

I strugling with some wierd behavior of the Property-Grid.
My application is built of some sort of a design cavas and elements being put/dragged into it.
Every element have a 'Settings' popup that contains the property-grid to display the settings.
The settings-model is build of some shallow hiererchy, for example:
    Settigns:
    - DisplayName
    - Color
    - Message-Details
    - - Type
    - - Message

The behavior is:
1. Opening the popup for the first time on one element - all good.
2. Opening the popup for the second time and in aother second element - the Grid now displays the internal object (Message-Details) properties doubled.

To illustarate:
    Settigns:
    - DisplayName
    - Color
    - Message-Details
    - - Type
    - - Message
    - - Type
    - - Message

This is how the object is displayed in the grid from that moment on, and for all elements (new or old) other than the first one the grid was opened for.

Any clue what is done wrong?
Any suggestion?

Thanks allot!

Comments (8)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm sorry you are having trouble.  This isn't something we've had reported and I'm not sure what could be causing it.  Could you please make a new simple sample project that shows it happening and send that to our support address, referencing this thread?  Make sure you remove any bin/obj folders in the ZIP file you send and rename the .zip file extension so it doesn't get spam blocked.  Then we can use that project to debug what's going on.  Kindly do this soon since we are planning on new maintenance releases in the next several days.


Actipro Software Support

Posted 6 years ago by Hagay
Avatar

I'm unable to isolate this case to a sample application for reproduction.

It is too much work to try to have it.

What do you suggest?

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

It really should just be a matter of creating a simple object/property structure like what you had above and what is used in your app.  Then put a PropertyGrid on a Window in a popup as you do in your app, point to the root object, and try to reproduce it that way.  We would need to be able to step through our code as it's happening to be able to assist with this scenario.

Alternatively if you can reproduce it in our own samples, that's fine too.  But either way, we need a sample to work with.  Thanks!


Actipro Software Support

Posted 6 years ago by Hagay
Avatar

I managed to reproduce it in a sample application.

I shared it by our organization's OneCloud: Link.

Password for zip: PropGridBug123

Let me know if you managed to get it...

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for the sample.  It appears that the problem is you are updating a property value in the midst of while our data factory is calling into the property to get its value, which triggers an invalid state.  In the sample, this is occuring here:

public class ParentModel : INotifyPropertyChanged {
  ...
  public ChildModel Child {
    get { return Child = _child ?? new ChildModel(); } // BAD
    set { SetProperty(ref _child, value); }
  }
  ...
}

I noticed you had another "GOOD" line in there commented out and that likely wouldn't cause the problem since you're not triggering INotifyPropertyChanged in that case.

I would actually suggest this code for your getter:

get {
  if (_child == null)
    _child = new ChildModel();
  return _child;
}

If you do that, it works great.


Actipro Software Support

Posted 6 years ago by Hagay
Avatar

As you see in my code, I did already understand the cause, as I explicitly stated GOOD/BAD.

However, I think this patern of lazy assignment/initialization of a property is legit and shouldn't cause this kind of behavior by the control.

In our case, indeed we need to use this kind of initialization.

No matter what was the flow that setted-up the Data-Object's state, the Property-Grid presents a faulty representation of it.

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I agree that we need to handle this situation better and we've made a change for the next build that handles it.

That being said, I still think you should be using the logic for your getter like what I posted because there isn't generally a need to do a full property set notification from a getter when it's the "initial" value being set.  That should be considered the default initial value that could have been set in the constructor.


Actipro Software Support

Posted 6 years ago by Hagay
Avatar

Will try to avoid this as you suggest.

Otherwise we will integrate the next build of your library.

Thank you for the support.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.