开发者

C# - Silverlight - Custom control or UserControl?

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 i开发者_开发问答t'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?


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜