c# - Cannot get WPF attached property via Reflection -
i have custom attached property in shared lib:
public class freezable { public static bool getisfrozen(dependencyobject obj) { return (bool)obj.getvalue(isfrozenproperty); } public static void setisfrozen(dependencyobject obj, bool value) { obj.setvalue(isfrozenproperty, value); } public static readonly dependencyproperty isfrozenproperty = dependencyproperty.registerattached("isfrozen", typeof(bool), typeof(uielement), new uipropertymetadata(false)); } this property tested in code , value stored.
freezable.setisfrozen(control, value); var correctvalue =freezable.getisfrozen(control); but trying property via reflection. , have exception property cannot find (getmethod null , setmethod null)!
public void findattachedproperty(type elementtype, string propertyname) { methodinfo getmethod = elementtype.getmethod("get" + propertyname, bindingflags.public | bindingflags.static); methodinfo setmethod = elementtype.getmethod("set" + propertyname, bindingflags.public | bindingflags.static); } canvas.left, canvas.right working , without problems. doing wrong , why cannot attached property!?
your code works fine me. best guess when calling findattachedproperty method giving system.windows.freezable elementtype instead of own implementation library.
Comments
Post a Comment