views:

26

answers:

1

I'm trying to create a control in Silverlight that inherits from Button so that I can perform a specific action everytime it is clicked. I'm doing this because I'd like to reuse this custom button in several locations with the same functionality.

I'd like to create the control in such a way so that I have a can set the custom Button's Content to a specific default icon image, but still have the rest of the button's style coming from either the default button style, or being automatically set by the toolkit Themes.

I'd also like to have the Content be described and editable in XAML rather than code if possible.

It seems like this would be a pretty common problem for Silverlight developers - is there a good way to tackle it?

A: 

If you use a normal button and edit an "Empty Template", then you can style the button to have any content you wish and expose properties that you can set in the XAML for Icons etc.

By using the standard button control, you will have all the behaviors that you require.

I believe this is what you're looking for, if not can you expand on your question.

--EDIT--

Ok, I get what you are trying to do now. So what you might want to consider is creating a custom button class that inherits from Button. Then you can override the OnClick method to handle your logic. When it comes to the XAML, you can create a template style for a TargetType of your custom button class, that would be styled to your requirements.

HTH, if you need some examples place a comment and I'll mock up some examples

Chris Nicol
I'm trying to avoid using Button.Click += DoStuff for the same button functionality in many places, so I'm creating a new class that inherits from Button, overriding the OnClick method so it does what I want, and then reusing the new button type.
grimus