(WPF)UserControl或CustomControl? [英] (WPF) UserControl or CustomControl?

查看:65
本文介绍了(WPF)UserControl或CustomControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个特定的交互式图形画布".

I need to build a specific interactive drawing "canvas".

在该画布中,用户将能够放置图形元素-与线链接的点.

In that canvas, user will be able to place graphic elements - points linked with lines.

我有一个准备好的WinForms UserControl- pointsList ,它表示画布中显示的点的列表.PointsList能够添加和删除点,并将它们链接到一行.

I have a ready WinForms UserControl - pointsList that represents the list of points presents in the canvas. PointsList is able to add and remove points, link them with a line.

pointsList 应该是画布中的浮动(可移动)且可调整大小的控件(如屏幕上的窗口).

pointsList should be a floating(movable) and resizeable control in the canvas(like a windows on a screen).

我的问题:

  1. 此画布"的最佳选择是什么-WPF UserControl或CustomControl ?
  2. 是否可以在WPF控件中放置一个(浮动的)WinForm UserControl ?
  3. 将很难在另一个控件中重写一个浮动且可调整大小的WPF用户控件吗?

编辑

"浮动控件"的更好解释:

想象一下WPF容器(例如Canvas).在此画布中,您有一个按钮.当您单击按钮时,浮动窗口控件"将在画布的内部中打开.

Imagine a WPF Container (say, a Canvas). In this canvas you have a button. When you click the button, a "Floating Window Control" opens inside the Canvas.

此控件就像Windows窗体一样,可以打开,移动,关闭,调整大小,但是所有这些都在父画布中.类似于MDI父级和子级表单,但父级不是表单,而是WPF容器(例如Canvas).

This control is like a Windows Form, can be opened, moved, closed, resized, but all this inside the parent canvas. Something similar to a MDI parent and child forms, but the parent is not a form, but a WPF container (say Canvas).

推荐答案

1)两种类型都将满足您的需求.UserControl通常更易于编写,特别是当您不熟悉WPF时.CustomControl实际上不是一个类,但是它意味着您扩展了一个现有控件.两种方法之间存在一些差异,最大的差异是自定义控件更易于使其具有主题性.在您的情况下,我认为这不是必需的,因此建议您使用UserControl.有关更多信息: http://www.wpftutorial.net/CustomVsUserControl.html

1) Both types will suit your needs. UserControls are typically easier to author, especially when you are new to WPF. CustomControl is actually not a class, but it means that you extend an existing control. There are some differences between the 2 approaches, the biggest one is that a custom control is easier to make it themeable. In your case, I assume this is not a need, so I'd recommend a UserControl. More info on this: http://www.wpftutorial.net/CustomVsUserControl.html

2)是.您可以使用WindowsFormsHost控件将WinForms控件放在WPF中.一个限制是WinForms控件必须是不透明的矩形,这意味着您不能以不同的形状投掷并期望它们正确地覆盖.寻找WindowsFormsHost,您会发现很多示例.

2) Yes. You can put a WinForms control inside WPF using the WindowsFormsHost control. One limitation is that the WinForms control must be a non-transparent rectangle, meaning you cannot throw in different shapes and expect them to overlay correctly. Look for WindowsFormsHost and you'll find lots of examples.

3)您能解释得更好吗?不了解您的意思,但是您当然可以将UserControl相互放置,并且WPF在处理动态大小调整时特别有用.

3) Can you explain better? don't understand what you mean, but of course you can place UserControls within each other, and WPF is especially useful when dealing with dynamic sizing.

这篇关于(WPF)UserControl或CustomControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆