开发者

Quickest way to inherit a standard control in WPF?

开发者 https://www.devze.com 2023-02-06 01:01 出处:网络
I just want to wrap a standard control with so开发者_如何学运维me more additional properties (look stay the same, I don\'t want to do theming in first stage).

I just want to wrap a standard control with so开发者_如何学运维me more additional properties (look stay the same, I don't want to do theming in first stage).

Can I just inherit from this standard control instead of UserControl or Control ? In fact I read it is obligatoryb to use Custom Control Project Template and not UserControl ontrol Project Template. Why ?

Update: I try with a Custom Control Project and inherit from the standard slider but I have nothing show up visually ! Now what should I do to have the same visual slider as the standard one ?

I know the difference between a user control and a custom control but in practice how do you do when you just want ONE single standard control ? How will a slider for example resize AUTOMATICALLY if I encapsulate it inside a User Control instead of a Custom Control ?


A custom control is a single control and can derive from another control, this would support styling. A UserControl is a composite control out of many different controls, and as a whole, doesn't support styling (the parts do however).

If you want to add features of any kind to an existing control, derive from it. If you want to pack several controls together to make it easier to handle them (you could still add DP's to it), use a UserControl.

A custom control alone won't do anything related to resizing etc, that is dependent on the settings you supply to it from the outside (ie. HorizontalAlignment, VerticalAlignment and others) when you used it in a container. The custom control should inherit the default template from the base class unless you override it.

0

精彩评论

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