Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

static variables and introductory dependency properties

$
0
0

So I just came upon the following statement:

public class MyClass:DependencyObject
{
 public static readonly 
      DependencyProperty MyDPProperty
          = DependencyProperty.Register(
                              "MyDP",
                              typeof(double),
                              typeof(MyClass));
}

 

The class now has a static DependencyProperty as a field but we now have another small problem.

The DependencyObject provides a setter and getter method but these infer the instance of the class from the current context. That is:

GetValue(MyDPProperty)

and

SetValue(MyDPProperty, value)

use "this" to determine the instance of the property that they should get or set. If you think about this you will realise that this means that you can only get and set a dependency property within the class or object that it belongs to.


That seems to make no sense as the dependency property is STATIC, there is only one copy for all instances.  There is thus no instance of the property.  What am I missing?


MarcinMR


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>