wpf - Get result of a Binding in code -
i'm searching wrong way, but:
is there way resulting value of binding through code?
probably glaring obvious, can't find it.
you need call edit: actually, that's not true... providevalue
method of binding. hard part need pass valid iserviceprovider
method...providevalue
returns bindingexpression
, not value of bound property.
you can use following trick:
class dummydo : dependencyobject { public object value { { return (object)getvalue(valueproperty); } set { setvalue(valueproperty, value); } } public static readonly dependencyproperty valueproperty = dependencyproperty.register("value", typeof(object), typeof(dummydo), new uipropertymetadata(null)); } public object evalbinding(binding b) { dummydo d = new dummydo(); bindingoperations.setbinding(d, dummydo.valueproperty, b); return d.value; } ... binding b = new binding("foo.bar.baz") { source = datacontext }; object value = evalbinding(b);
not elegant, works...
Comments
Post a Comment