开发者

How to inherit from silverlight Button?

I need to have button have 4 images that are changed by the appl开发者_运维问答ication action.

I want to define new class ButtonEx that inherit from the Button class.

So, i did it by adding 'silverlight template control' and it to be inherit from control to Button.

Now, i cant see the images whan i put this ButtonEx on the page.

What i did wrong ?

How to fix it ?

( same code work fine in WPF )


Can you post any of your code? Did you create a visual style for it in themes\generic.xaml? Did you set the default style key?

I recently followed this tutuorial for a TextBox, you could so something similar for your button... http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx


Store your images as resources then create a user control that has - a button and the content of the button is an image - a property to select the image from the resources

use the usercontrol as your button.


please post a code sample...

to inherit form button you simply need this.

public class ButtonEx:Button

{

}

this will have all functionality that button has. if you want new template just add it in Themes/generic.xaml


From your question its not clear that you really need to be subclassing Button. Maybe you can get by with just copying and modifying the template of button (Blend helps for this), or just have the image as content bound to some property for the application to change (using a ValueConverter perhaps).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜