开发者

Best way to modify Button behavior and Content, but maintain styles?

I'm trying to create a control in Silverlight that inherits from Button so that I can perfo开发者_StackOverflow中文版rm 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜