wpf - Is there a way to know of what type is the property bound to my DependencyProperty? -


i know type bound dependencyproperty of control. there way know that?

i have dependencyproperty this:

public static readonly dependencyproperty myvalueproperty =         dependencyproperty.register("myvalue", typeof(double?), typeof(mycontrol),                                     new frameworkpropertymetadata                                         {                                             bindstwowaybydefault = true,                                             defaultupdatesourcetrigger = updatesourcetrigger.propertychanged,                                             propertychangedcallback = onmyvaluechanged                                         });      public double? myvalue     {         { return (double?)getvalue(myvalueproperty); }         set { setvalue(myvalueproperty, value); }     } 

this property of control, , people can use like:

<mynamespace:mycontrol myvalue="{binding theirproperty}"/> 

theirproperty can anything, know actual type of theirproperty inside control, possible?

i tried checking on bindingoperations, couldn't find anything. know, example if binding double or double?.

there no publicly exposed property on bindingexpression can source type stored in private field i.e. _sourcetype can via reflection:

private static void onmyvaluechanged(dependencyobject d,                                       dependencypropertychangedeventargs args) {    var bindingexpression = bindingoperations.getbindingexpression(d,                                               mycontrol.myvalueproperty);    type sourcetype = (type)bindingexpression.gettype()                          .getfield("_sourcetype", bindingflags.nonpublic |                               bindingflags.instance).getvalue(bindingexpression);    bool isnullabledouble = sourcetype == typeof(double?);    bool isdouble = sourcetype == typeof(double); } 

also stored in private getter property convertersourcetype can used source type:

type sourcetype = (type)bindingexpression.gettype()                   .getproperty("convertersourcetype", bindingflags.instance |                               bindingflags.nonpublic).getgetmethod(true)                              .invoke(bindingexpression, null); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -