WPF: instances of usercontrol share dependency properties -


i made usercontrol , works great, when put 2 instances of control 1 window, last of them works. tried find solution , realized, dependency properties shared, dont know how work.

here dependency property:

    public double animatingverticaloffset     {         { return (double)getvalue(animatingverticaloffsetproperty); }         set { setvalue(animatingverticaloffsetproperty, value); }     }      public static readonly dependencyproperty animatingverticaloffsetproperty;      static listchooser()     {         listchooser.animatingverticaloffsetproperty =                    dependencyproperty.register("animatingverticaloffset", typeof(double), typeof(listchooser), new uipropertymetadata(onanimationverticaloffsetchanged));     } 

the dependency property must static no ties 1 single instance. , applies callbacks (onanimationverticaloffsetchanged in case) - these must static methods (don't worry, object instance passed via parameter, have type casting ensure object type working with).

you should use static initializer initialize dp, method used (initializing in constructor) works, dp overwrite each instance.

see question deeper explanation.

edit:

corrected code:

public double animatingverticaloffset {     { return (double)getvalue(animatingverticaloffsetproperty); }     set { setvalue(animatingverticaloffsetproperty, value); } }  public static readonly dependencyproperty animatingverticaloffsetproperty =                dependencyproperty.register("animatingverticaloffset", typeof(double), typeof(listchooser), new uipropertymetadata(onanimationverticaloffsetchanged));  static listchooser() { } 

if callback not static, compile error (=> have make static).

edit:

remember, dp definition static, not property's value itself! dps work other property, has features: value inhertiance, bidnings, animation...


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -