gpt4 book ai didi

wpf - WPF/Silverlight 中的 UIElement 与 FrameworkElement

转载 作者:行者123 更新时间:2023-12-03 23:30:46 26 4
gpt4 key购买 nike

我什么时候从 UIElement 派生和 FrameworkElement考虑 FrameworkElement继承 UIElement .任何人都可以举出现实生活中的例子吗?

最佳答案

This is a good page for learning about WPF Architecture ,此答案仅适用于 WPF。如果您有时间,请查看 UIElementFrameworkElement 部分以及其余部分。这是来自链接页面的引述,解释了为什么存在 2 个级别:

To this point in the topic, "core" features of WPF – features implemented in the PresentationCore assembly, have been the focus. When building WPF, a clean separation between foundational pieces (like the contract for layout with Measure and Arrange) and framework pieces (like the implementation of a specific layout like Grid) was the desired outcome. The goal was to provide an extensibility point low in the stack that would allow external developers to create their own frameworks if needed.



简而言之, UIElement 知道如何绘制自己(因为它们是从 Visual 派生的)。他们还可以通过提供 OnPreviewMouseDownOnMouseDown 等虚拟方法来使用 routed events system,并通过实现 MeasureArrange 来使用 layout system 的一部分。
FrameworkElement 通过实现 UIElement 中定义的一些虚拟方法来扩展布局系统。它们提供了设置布局属性的一致方式,例如 Margin 属性和 MinWidth 属性。此外,可以设置样式,并且可以参与 data binding

在回答您的问题时,如果您需要 FrameworkElement 添加的任何额外功能,例如您需要更易于使用的样式、绑定(bind)或布局系统,然后从中派生。否则,从 UIElement 派生,因为使用 FrameworkElement 会有一点开销。

此外,您应该查看 Control 类(派生自 FrameworkElement ),因为它们提供了有用的新功能层,如 Templating 和属性,如 Padding

熟悉 inheritance hierarchy 也是一个好主意,您可能希望从其中的其他类派生(尽管可能没有比 Visual 更高的链)。

关于wpf - WPF/Silverlight 中的 UIElement 与 FrameworkElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5956880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com