中继承标准控件的最快方法

中继承标准控件的最快方法

本文介绍了在 WPF 中继承标准控件的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想用更多的附加属性包装一个标准控件(看起来保持不变,我不想在第一阶段做主题).

I just want to wrap a standard control with some more additional properties (look stay the same, I don't want to do theming in first stage).

我可以只继承这个标准控件而不是 UserControl 或 Control 吗?事实上,我读到使用自定义控件项目模板而不是 UserControl 控制项目模板是必须的.为什么?

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 ?

推荐答案

自定义控件是单个控件,可以从另一个控件派生,这将支持样式.UserControl 是由许多不同控件组成的复合控件,并且作为一个整体,不支持样式(但部分支持).

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).

如果您想向现有控件添加任何类型的功能,请从它派生.如果您想将多个控件打包在一起以使其更易于处理(您仍然可以向其中添加 DP),请使用 UserControl.

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.

单独的自定义控件不会做任何与调整大小等相关的事情,这取决于您从外部提供给它的设置(即.Horizo​​ntalAlignmentVerticalAlignment和其他)当您在容器中使用它时.自定义控件应该从基类继承默认模板,除非您覆盖它.

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.

这篇关于在 WPF 中继承标准控件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:49