views:

172

answers:

2

I need a button that is visually completely customizable, but has custom logic to publish events and manage it's visual state based on events it has registered for.

When I say visually customizable, I mean I should be able to both create the button in xaml and set it's style by binding to the supplied style. Or I can create an instance of the button and set the style by passing a parameter to an alternate constructor. Or by calling a method on the button class to set the style.

I do not plan on substituting the controls template, it should be a button. Can anyone point me to some code samples of this?

A: 

If you don't want to allow the control to be templated (I would generally recommend you do, but you don't have to) than a UserControl would work well. A simple user control that exposes a ButtonStyle property that is applied to a specific control should solve your needs.

Stephan
Making this into a custom control would take much more work wouldn't it?
cmaduro
How do I provide its template through the constructor?
cmaduro
I wanted to state of the control (active/inactive) to be handled internally, but that does not apply to all types of controls. Say I user wants to load a ViewB clicking a button for that, then that button would be rendered as active. If they user needed to select ViewB from a dropdown then there is no active state.
cmaduro
I guess i'm looking for something akin to the hyperlinkbutton.
cmaduro
Are you wanting to template the control yourself or let the users of the your control retemplate what the button should look like?
Stephan
The control is a button, but the user can change the style for the base state and other states.
cmaduro
A: 

Totally depends on your application. I create ContentControl derivatives much more often than UserControl, if only for the glint of hope that they may be useful in the future.

I have written before:

UserControls are content controls that are optimized for simple design-time use, typically for sharing within an application, but not with other applications.

Component libraries should never contain UserControl implementations.

Jeff Wilcox