WPF Attached Property Data Binding -


i try use binding attached property. can't working.

public class attached {     public static dependencyproperty testproperty =         dependencyproperty.registerattached("testproperty", typeof(bool), typeof(attached),         new frameworkpropertymetadata(false, frameworkpropertymetadataoptions.bindstwowaybydefault | frameworkpropertymetadataoptions.inherits));      public static bool gettest(dependencyobject obj)     {         return (bool)obj.getvalue(testproperty);     }      public static void settest(dependencyobject obj, bool value)     {         obj.setvalue(testproperty, value);     } } 

the xaml code:

<window ...>     <stackpanel local:attached.test="true" x:name="f">         <checkbox local:attached.test="true" ischecked="{binding (local:attached.test), mode=twoway, relativesource={relativesource self}}" />         <checkbox local:attached.test="true" ischecked="{binding (local:attached.test), mode=twoway}" />     </stackpanel> </window> 

and binding error:

system.windows.data error: 40 : bindingexpression path error: '(local:attached.test)' property not found on 'object' ''stackpanel' (name='f')'. bindingexpression:path=(local:attached.test); dataitem='stackpanel' (name='f'); target element 'checkbox' (name=''); target property 'ischecked' (type 'nullable`1') 

believe or not, add path= , use parenthesis when binding attached property:

ischecked="{binding path=(local:attached.test), mode=twoway, relativesource={relativesource self}}" 

in addition, call registerattached should pass in "test" property name, not "testproperty".


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -