wpf - How to deal with a dependency Property that is already registered -


i have dependencyproperty declared so;

    public readonly showhideaddbuttonproperty dependencyproperty = dependencyproperty.register("showhideaddbutton", gettype(boolean), gettype(datanavigator), new frameworkpropertymetadata(true, frameworkpropertymetadataoptions.affectsrender, new propertychangedcallback(addressof onshowhideaddbuttonchanged))) 

it forms part of standalone usercontrol i'm building (both because useful me in future , because it's way learn). when control first added project , project run works well, thereafter throws arguementexception message stating 'showhideaddbutton' property registered 'mycontrol'.

so 1 started looking possibility of unregistering dependency property appear not idea. 2 questions arise this.

to add further clarity, in light of answer below here full code relating dependency property. making method shared causes 'showhideaddbutton' , 'add' throw same error mentioned in comment answer.

public shared readonly showhideaddbuttonproperty dependencyproperty = dependencyproperty.register("showhideaddbutton", gettype(boolean), gettype(datanavigator), new frameworkpropertymetadata(true, frameworkpropertymetadataoptions.affectsrender, new propertychangedcallback(addressof onshowhideaddbuttonchanged)))  '''//////////////////////////////////////////////////////////////////////////////////////////////////// ''' <summary> ''' gets or sets value indicating whether hide add button shown. ''' </summary> ''' ''' <value> true if show hide add button, false if not. </value> '''////////////////////////////////////////////////////////////////////////////////////////////////////  <description("set visibility of add button on navigator control"), category("navigator buttons visibility")> public property showhideaddbutton boolean             return cbool(getvalue(showhideaddbuttonproperty))     end     set(byval value boolean)         setvalue(showhideaddbuttonproperty, value)     end set end property  private shared sub onshowhideaddbuttonchanged()     if showhideaddbutton = true 'this throws error add below         add.visibility = windows.visibility.visible 'add being button visibility changed     else         add.visibility = windows.visibility.collapsed     end if  end sub 

1) why error occurring in first place...presumably it's error in original code, compiles without error i'm not sure might be?

2) sufficient wrap offending line in try catch block catch offending error doable doesn't solve problem or inform me why it's happening in first place.

some additional info:

the actual control looks not unlike this: enter image description here

it comprised of number of separate buttons , textboxes, , in case of problem dependencyproperty showhideaddbutton property of datanavigator control needs trigger visibility of button named addbutton in control. problem trying figure out how refer button.

thanks

the new dependency property declared shall static (shared in vb.net): public shared readonly showhideaddbuttonproperty dependencyproperty = dependencyproperty.register("showhideaddbutton", gettype(boolean), gettype(datanavigator), new frameworkpropertymetadata(true, frameworkpropertymetadataoptions.affectsrender, new propertychangedcallback(addressof onshowhideaddbuttonchanged))) check out: dependencyproperty class

the propertychangedcallback needs changed propertymetadata in dependencyproperty.register. onshowhideaddbuttonchanged method's paramter signature needs changed (dependencyobject dependencyobject, dependencypropertychangedeventargs eventargs). finally, in method, can reach control var control = dependecyobject yourcontrol. therefore can reach instance fields, properties , methods in static method.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -