有没有办法设置 UIElement 的大小(无需转换为 FrameworkElement),可能类似于在UIElement 镜像通过 FrameworkElement 上的 ActualWidth 和 ActualHeight 获取大小信息?
实际上,我猜你可以说我想设置 UIElement 的RenderSize。
我正在考虑一种方法,该方法能够以某种方式强制执行具有所需大小的测量/安排通过,但似乎无法找到合适的攻击点。
请您参考如下方法:
这似乎是一个简单或明显的答案,但不,您不能设置 UIElement 的 Width 或 Height仅仅是因为它没有这些属性。 UIElement 类只是一个 WPF 核心级实现的基类,它提供一些基本功能。来自UIElement Class在 MSDN 上:
A UIElement has the following capabilities that are specifically defined by the UIElement class:
• Can render as a child element (UIElement derives from Visual, a high level graphics class)
• Contains logic that is used to size and position possible child elements of a UIElement (when interpreted by a layout system)
• Can respond to user input (including control of where input is getting sent to via their handling of event routing, or routing of commands)
• Can raise routed events that travel a route through the logical element tree
• Supports some aspects of the animation system
现在查看 FrameworkElement Class MSDN 上的页面,我们看到了这个:
FrameworkElement extends UIElement and adds the following capabilities:
• Layout system definition: FrameworkElement provides specific WPF framework-level implementations for certain methods that were defined as virtual members in UIElement. Most notably, FrameworkElement seals certain WPF core-level layout overrides, and instead provides a WPF framework-level equivalent that derived classes should override instead. For example, FrameworkElement seals ArrangeCore but provides ArrangeOverride. These changes reflect the fact that at the WPF framework-level there is a full layout system in place that can render any FrameworkElement derived class. At the WPF core level, certain members that will structure a general WPF based layout solution are in place, but the actual engine of the layout system is not defined.
我突出显示的粗体文本应该进一步解释为什么您不能设置 UIElement 的 Width 或 Height。
