- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道我的 StackPanel
所有项目的高度。
有什么区别:
Height
- 获取或设置元素的建议高度。 ActualHeight
- 获取该元素的渲染高度。 (只读)ExtentHeight
- 获取包含范围垂直大小的值。 (只读)ViewportHeight
- 获取包含内容视口(viewport)的垂直尺寸的值。 (只读)DesiredSize
- 获取该元素在布局过程的测量过程中计算的大小。 (只读)RenderSize
- 获取(或设置,但请参阅备注)此元素的最终渲染大小。来自 MSDN:
Height
Gets or sets the suggested height of the element.Property value:
Double
- The height of the element, in device-independent units (1/96th inch per unit).The height of the element, in device-independent units (1/96th inch per unit).
ActualHeight (chỉ đọc)
Gets the rendered height of this element.Property value:
Double
- The element's height, as a value in device-independent units (1/96th inch per unit).This property is a calculated value based on other height inputs, and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Height that are the basis of the input change.
Because ActualHeight is a calculated value, you should be aware that there could be multiple or incremental reported changes to it as a result of various operations by the layout system. The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on.
ExtentHeight (chỉ đọc)
Gets a value that contains the vertical size of the extent.Property height:
Double
- A Double that represents the vertical size of the extent.The returned value is described in Device Independent Pixels.
ViewportHeight (chỉ đọc)
Gets a value that contains the vertical size of the content's viewport.Property value:
Double
- The Double that represents the vertical size of the content's viewport.The returned value is described in Device Independent Pixels.
DesiredSize (chỉ đọc)
Gets the size that this element computed during the measure pass of the layout process.Property value:
Size
- The computed size, which becomes the desired size for the arrange pass.The value returned by this property will only be a valid measurement if the value of the IsMeasureValid property is true.
DesiredSize is typically checked as one of the measurement factors when you implement layout behavior overrides such as ArrangeOverride, MeasureOverride, or OnRender (in the OnRender case, you might check RenderSize instead, but this depends on your implementation). Depending on the scenario, DesiredSize might be fully respected by your implementation logic, constraints on DesiredSize might be applied, and such constraints might also change other characteristics of either the parent element or child element. For example, a control that supports scrollable regions (but chooses not to derive from the WPF framework-level controls that already enable scrollable regions) could compare available size to DesiredSize. The control could then set an internal state that enabled scrollbars in the UI for that control. Or, DesiredSize could potentially also be ignored in certain scenarios.
<小时>小时>RenderSize Gets the final render size of this element.
Property value:
Size
- The rendered size for this element.This property can be used for checking the applicable render size within layout system overrides such as OnRender or GetLayoutClip.
A more common scenario is handling the SizeChanged event with the class handler override or the OnRenderSizeChanged event.
就我而言,我想知道 StackPanel
中所有项目的所需高度。
换句话说:我想知道 StackPanel 中所有项目的高度(在绘制之前),如果它们溢出面板,我会
确保它们适合StackPanel的项目。
这意味着我可能希望在调整大小事件期间获得所需高度(ExtentHeight?DesiredSize?)(SizeChanged?LayoutUpdated?) - 在任何事件之前绘图发生(因此速度更快)。
这些属性中的大多数返回零;显然,我不知道这些属性的含义,也没有在文档中进行解释。
1 Câu trả lời
如您所知,StackPanel
是一个 [Panel] 对象。每个面板通过两种方法与其子面板进行通信,以确定最终的尺寸和位置。第一个方法是 MeasureOverride
,第二个方法是 ArrangeOverride
.
MeasureOveride 会询问每个子项所需的大小以及给定的可用空间量。ArrangeOverride
在测量完成后排列子项。
让我们创建一个堆栈面板:
public class AnotherStackPanel : Panel
{
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register(“Orientation”, typeof(Orientation),
typeof(SimpleStackPanel), new FrameworkPropertyMetadata(
Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsMeasure));
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}
protected override Size MeasureOverride(Size availableSize)
{
Size desiredSize = new Size();
if (Orientation == Orientation.Vertical)
availableSize.Height = Double.PositiveInfinity;
khác
availableSize.Width = Double.PositiveInfinity;
foreach (UIElement child in this.Children)
{
if (child != null)
{
child.Measure(availableSize);
if (Orientation == Orientation.Vertical)
{
desiredSize.Width = Math.Max(desiredSize.Width,
child.DesiredSize.Width);
desiredSize.Height += child.DesiredSize.Height;
}
khác
{
desiredSize.Height = Math.Max(desiredSize.Height,
child.DesiredSize.Height);
desiredSize.Width += child.DesiredSize.Width;
}
}
}
return desiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
double offset = 0;
foreach (UIElement child in this.Children)
{
if (child != null)
{
if (Orientation == Orientation.Vertical)
{
child.Arrange(new Rect(0, offset, finalSize.Width,
child.DesiredSize.Height));
offset += child.DesiredSize.Height;
}
khác
{
child.Arrange(new Rect(offset, 0, child.DesiredSize.Width,
finalSize.Height));
offset += child.DesiredSize.Width;
}
}
}
return finalSize;
}
}
DesiredSize
(大小由 MeasureOverride
返回)是总和子项大小的方向StackPanel 和最大的尺寸 child 在另一个方向。
RenderSize
代表最终的布局后 StackPanel
的大小已完成。
ActualHeight
VàRenderSize.Height
.要依赖这些属性,您应该仅在 LayoutUpdated 的事件处理程序中访问它们。事件。
关于wpf - Stackpanel:高度 vs ActualHeight vs ExtentHeight vs ViewportHeight vs DesiredSize vs RenderSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6403091/
我正在尝试在窗口显示之前计算 StackPanel width, height(位于网格的中间单元格)(例如窗口构造函数)。如何实现?
我在运行时创建了一个 StackPanel,我想像这样测量 StackPanel 的 Height: StackPanel panel = new StackPanel(); panel.Childr
我尝试创建一个具有半透明圆形背景的自定义控件: 问题是我可能无法绑定(bind)到 ActualHeight/ActualWidth 属性,因为它们不是依赖项。 如何使矩形和文
我有一个带有 TextBlock 的 Canvas,如下所示: 我
不,我没有像其他许多人一样将 ActualHeight 设置为零的问题。在我的 Windows 应用商店应用程序 (WinRT) 中,我在调试器中看到了这一点: ActualHeight | 50.7
我需要一个 Viewport3D仅用于使用 Petzold.Media3D.ViewportInfo 进行几何计算.我宁愿不必将它放在 Window 中。或以其他方式呈现它。 我试图通过实例化 Vie
我有两个单独的 ItemsControl s 并排出现。 ItemsControl s 绑定(bind)到同一个 ItemsSource ,但它们以不同的方式显示数据。 左侧显示的每个项目很可能比右侧
我想将 WPF 路径添加到 InkCanvas并使用选择来选择 WPF 路径。 所以,我使用这个代码。 System.Windows.Shapes.Path path = drawCanvas.Chi
最近我遇到了一个看似简单的问题:我想在我正在处理的一个应用程序中使用 Mode=OneWayToSource 将 Canvas 的 Width 和 Height 参数推送到 ViewModel 中。原
我在 Canvas 中有一个 Grid ,定义如下:
Tôi muốn biết chiều cao của tất cả các mục trong StackPanel của tôi. Sự khác biệt là gì: Chiều cao - Lấy hoặc đặt chiều cao được đề xuất của phần tử. ActualHeight - Lấy chiều cao được hiển thị của phần tử. (Chỉ đọc) ExtentHeight
Tôi là một lập trình viên xuất sắc, rất giỏi!