gpt4 book ai didi

c# - 有没有办法设置 UIElement 的宽度和高度?

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:19 25 4
gpt4 key购买 nike

有没有办法设置 UIElement 的大小(无需转换为 FrameworkElement),可能类似于在UIElement 镜像通过 FrameworkElement 上的 ActualWidthActualHeight 获取大小信息?

实际上,我猜你可以说我想设置 UIElementRenderSize

我正在考虑一种方法,该方法能够以某种方式强制执行具有所需大小的测量/安排通过,但似乎无法找到合适的攻击点。

最佳答案

这似乎是一个简单或明显的答案,但不,您不能设置 UIElementWidthHeight仅仅是因为它没有这些属性。 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.

我突出显示的粗体文本应该进一步解释为什么您不能设置 UIElementWidthHeight

关于c# - 有没有办法设置 UIElement 的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144810/

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