c# - Automatically bind event to a Dependency Properties Value -


i trying set custom user control derived togglebutton control.

i set 2 new commands, checkedcommand , uncheckedcommand.

i have defined commands below, , able bind them. , firing them via internal events. works great.

however able have these commands disable button usual command interface canexecute. understand need use canexecutechanged event , set isenabled property in here. when supposed bind event, looked @ using propertychangedcallback event of dependancyproperty how unsubscribe bound command.

it ends looking bit convoluted, missing simple or way is.

        [description("checked command"), category("common properties")]         public icommand checkedcommand         {             { return (icommand)this.getvalue(checkedcommandproperty); }             set { this.setvalue(checkedcommandproperty, value); }         }         public static readonly dependencyproperty checkedcommandproperty = dependencyproperty.register(           "checkedcommand", typeof(icommand), typeof(toggletextbutton)); 

i may not understand specific requirements in general wouldn't this. wpf has been designed data-driven, whereas here you're implementing event-driven notification. events old-school winforms way of doing things , added facilitate easier transition winforms new data-bound architecture.

imo more "correct" solution here expose boolean dependency property i.e. same thing "checked" property in checkbox. users of control can bind 1 property boolean property in view models setter called whenever state changes. second "enabled" dp allow both , user control whether or not control should enabled, again similar how it's implemented in checkbox.

to ask obvious question though if it's checkbox functionality you're after why aren't templating checkbox? need usercontrol you're trying achieve?


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -