English 中文(简体)
B. 扩大对世界森林基金用户的控制
原标题:Extending user controls in WPF

我与往常一样建立了用户控制,由XAML部分和编码背后部分组成。 现在,我需要创建另一种用户控制,这种控制与前者的一些功能相同,但这种控制有不同的观点,也可能在编码背后有其他特点。

我的第一个想法是建立一个接口,以收集这两类管制的共同功能。 这是正确的道路吗? 我如何管理我应该拥有的不同XAML部分? 任何建议都值得欢迎。

最佳回答

我想补充一下我认为对面临同样情况的其他人可能有用的另一项贡献。

One other possible solution, which in my opinion is suitable if the controls you are going to create are not particularly complex, is to create a base User Control containing the common features that you want to share: such control will be written entirely in C#. This, in fact, allows inheritance in User Controls composed of both XAML and code behind. In the XAML of the inherited control, rather than having

<UserControl> ... </UserControl>

<MyProject: MyBaseControl x:Class="MyProject.MyExtendedControl"> ... </MyProject: MyBaseControl>

之后,在你后面的法典中,还需要具体说明如下:

class MyExtendedControl : MyBaseControl

希望这一帮助。

问题回答

用户控制不给妇女论坛的继承带来好处,但你可以做一些工作,但总体而言,你可能更不用使用习俗控制。 比较容易地确定使用这种技术进行继承控制的不同XAML。 开始实行海关管制的最容易的方法是,在你的“海关控制”项目中增加一个新项目,这将增加控制,并将XAML加入到Themes/generic。 页: 1

To inherit from this control, the easiest way is to add another new Custom Control (WPF) and then change the code behind to inherit from your parent control instead of Control.

有许多办法可以分割这些零件,使其更容易工作。

正如在评论中提到的,磁力控制仪依靠数据约束将投入控制与逻辑分开。 通过设置适当类别,以体现您控制的数据内容,你可以改变行为。 如果不同用途之间的差别不大,则你的数据目录或观点模型可实施可见性特性,显示和隐藏不同内容。

Another way to break apart functionality is by Aggregation. See StackOverflow 269496

你们可以建立较小的管制,实施共同功能,然后通过合并较小的控制(即合并控制)来建立更大的特殊目的控制。 汇总工作将针对编码背后的做法和数据约束办法。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签