notanaverageman / Bindables

Bindables converts your auto properties into Wpf dependency or attached properties.
MIT License
52 stars 9 forks source link

Cannot get DependencyPropertyDescriptor #16

Closed RodgerLeblanc closed 5 years ago

RodgerLeblanc commented 5 years ago

I'm using Bindables.Fody 0.4.0 with Fody 2.1.2, decided to upgrade to 4.0 today.

To get a Bindables DP at runtime, I used to get it like this :

DependencyPropertyDescriptor dependencyPropertyDescriptor =
    DependencyPropertyDescriptor.FromName(
        nameof(Test),
        typeof(MainWindow),
        typeof(MainWindow));

It worked well before, but now it always return null. Maybe your code is not to blame as I can reproduce this behavior when leaving Bindables.Fody at 0.4 and updating Fody to 3.0.

Do you know why this happens? Any other way to get a reference to the DP at runtime?

I've tried the code from a MSDN post and it results in the same behavior.

DependencyProperty dp = (DependencyProperty)typeof(MainWindow).GetField("TestProperty").GetValue(this);

Here's a sample project with Bindables.Fody 0.4 and Fody 2.0, it runs correctly, updating either Bindables or Fody will result in a custom exception being thrown.

BindablesDependencyPropertyDescriptor.zip

notanaverageman commented 5 years ago

Have you tried to match the Fody version? These are the Fody versions required by each version:

 - 0.3.* -> Fody [1, 2)
 - 0.4.* -> Fody [2, 3)
 - 0.5.* -> Fody [3, 4)
 - 4.*   -> Fody [4, 5)

If it does not solve the problem you can check the FodyWeavers.xml file. There should be a Bindables entry in that file.

RodgerLeblanc commented 5 years ago

You're absolutely right, by trying to isolate things in a dummy project, I forgot to include Bindables in FodyWeavers, everything works as expected with Bindables 4.x and Fody 4.x.

Thanks for pointing me to the obvious!