在 Winform 应用程序中使用 ElementHost 托管 WPF UserControl 有什么缺点吗?

发布于 2024-08-21 20:10:32 字数 1227 浏览 6 评论 0原文

好奇使用 ElementHost 是否有任何缺点 在 Winform 应用程序中托管 WPF UserControl?

我之所以这么问,是因为我觉得创建一个新的 WPF 应用程序需要花费很多时间,并且其基本界面看起来还不错。体面的意思是,如果我创建一个新的 Winforms 应用程序并在其上添加一些控件,我最终会得到一个基本界面,其外观和行为与许多其他应用程序类似,但看起来并不简单。如果我对 WPF 应用程序做同样的事情,我感觉不会获得相同的结果,我最终会得到一个带有白色背景的“普通”应用程序,除非我将角色更改为设计师并花费额外的时间使其看起来特定方式。

然而,在某些情况下,我需要 WPF,因为它相对容易创建风格化界面。考虑一个视频播放器控件;在 WPF 中,我可以创建一些看起来非常漂亮且自定义的东西,但比 Winforms 控件花费的时间和精力要少得多。在这些情况下,我使用 WPF 是有意义的,因为我最终花费的时间比覆盖 OnPaint 的时间要少:-)。

我意识到我使用了很多主观术语,但这是我最初问题背后的推理。

更新:

只是为了澄清我的“视频播放器控制”示例。 WPF 不仅为我提供了 MediaElement 来播放,而且如果我想说,当视频暂停时或者我想要半透明的“播放/暂停/停止”时,在视频上覆盖一个“播放”按钮/volume”栏在鼠标位于某个位置时显示,WPF 使这比任何 Winforms 替代方案简单得多。

编辑:

也许我的配置选项错误或其他什么,但当我查看 WPF 与 Winforms 控件时,“描述”部分消失也令人沮丧。更令人沮丧的是,在 WPF 属性表单中按 F1 不会将您带到您所在的特定属性/事件。

更新:

还有其他人吗?我更关心将 WPF UserControl 托管在 ElementHost。到目前为止,听起来似乎存在运行时的一次性开销,但这就是全部吗?

Curious if there are any disadvantages to using an ElementHost to host a WPF UserControl in a Winform application?

I ask because in general I feel that it takes to much time for me create a new WPF application with a basic interface that looks decent. Decent in the sense that if I create a new Winforms application and throw some controls on it I end up with a basic interface that looks and behaves similar to many other applications but doesn't look plain. If I do the same thing with a WPF application I don't feel I achieve the same results, I end up with a "plain" application with a white background unless I change roles to designer and spend extra time to make it look a certain way.

However there are cases where WPF is desirable to me for it's relative ease of creating a stylized interface. Consider a video player control; in WPF I can create something that looks very nice and custom but took much less time and effort than a Winforms control. In these cases it makes sense for me to use WPF since I end up spending less time than I would have overiding OnPaint :-).

I realize I'm using a lot of subjective terms but this is my reasoning behind the original question.

Update:

Just to clarify my "video player control" example. Not only does WPF give me the MediaElement to play with but if I want to say, overlay a Play button on the video when it is paused or if I wanted a semi-transparent "play/pause/stop/volume" bar to show up when the mouse in in a certain location, WPF makes that much simpler than any Winforms alternative.

Edit:

Maybe I have a configuration option wrong or something but it's also frustrating the the "Description" section disappears when I am looking at a WPF vs. Winforms Control. Even more frustrating that pressing F1 in a WPF property form doesn't take you to the specific property/event you were on.

Update:

Any one else? I'm more concerned about performance impacts and/or feature limitations that would be introduced by hosting the WPF UserControl in an ElementHost. So far it sounds like there is the onetime overhead of the runtime but is that all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缺⑴份安定 2024-08-28 20:10:32

我看到了一些潜在的缺点。

首先,您现在有两种方式显示 UI。从维护的角度来看,这可能会出现问题,具体取决于开发人员接触代码的情况。

其次,WPF 确实有一个与之关联的运行时(用于调度事件、依赖属性管理等),但它是一次性成本。如果您将其用于少量控件,那么您将根据其使用量支付相对较大的成本。

我不会说这些会破坏交易,这完全取决于您的应用程序和您的团队。

I see a few potential disadvantages.

First, you now have two ways of displaying UI. This can present issues from a maintenance point of view depending the developers touching the code.

Second, WPF does have a runtime associated with it (for dispatching events, dependency property management, etc, etc), but it's a one-time cost. If you are using that for a small number of controls, then you are paying a relatively large cost in proportion to it's usage.

I wouldn't say these are deal-breakers, it's all dependent on your app and your team.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文