Noesis / Managed

NoesisGUI Managed SDK
Other
94 stars 14 forks source link

DependencyProperty.UnsetValue is not recreated after reinitialization #11

Closed aienabled closed 6 months ago

aienabled commented 1 year ago

Hi guys, after upgrading from 3.0.12 to 3.2.1 I've noticed a major issue: DataTriggers stops working after NoesisGUI reinitialization (Shutdown and then Init). After debugging I have found out that the DependencyProperty.UnsetValue object is disposed (swigCPtr.Handle equals zero) so DataTrigger comparison returns incorrect result.

As I see, two years ago in 3.1.0 you've made an optimization by creating the DependencyProperty.UnsetValue object only once. Now I realize why 3.1.0 was broken for me among some other issues (so I've skipped it). https://github.com/Noesis/Managed/blob/0990dc8d64e1db96a5550db17f1f5700490ead5f/Src/Noesis/Core/Src/Proxies/DependencyProperty.cs#L34

I've made a straightforward fix like this:

  private static NamedObject unsetValue;

  public static object UnsetValue
  {
    get
    {
      if (unsetValue is null
          || ((NamedObject)unsetValue).IsDisposed)
      {
          unsetValue = new NamedObject("DependencyProperty.UnsetValue", UnsetValuePtr);
      }

      return unsetValue;
    }
  }

However I'm not sure if it's a valid fix as there could be other cases where a similar issue may appear. I've found the same issue with Binding.DoNothing https://github.com/Noesis/Managed/blob/0990dc8d64e1db96a5550db17f1f5700490ead5f/Src/Noesis/Core/Src/Proxies/Binding.cs#L42

Regards! Vladimir

s-fernandez-v commented 1 year ago

Hi Vladimir, I think your change is safe and we are going to integrate it. Thanks a lot for reporting and providing the patch!

s-fernandez-v commented 6 months ago

Already fixed and included in latest release