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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -