0

我需要创建带有一些隐藏列的 Grid 快照(通过将其设置为 ColumnDefinition.Width = 0)。

在屏幕上看起来不错,但created image所有列都可见(does not respect the ColumnDefinitions)。我在某处发红,这是因为 RenderTargetBitmap 正在查看不存在这些更改的不同层(视觉层与布局层)。是否有机会使用正确的 ColumnDefinitions 获得网格的真实快照?我不能简单地使用 Rectagnel.Fill = VisualBrush,因为我需要循环存储这些图像(每次迭代 = 新图像)。

我尝试了像这个片段这样的方法

4

2 回答 2

1

UpdateLayout()在每个快照之前都需要强制。我在循环中更改了尺寸,并且布局更新得太晚了。

于 2011-11-16T14:55:22.563 回答
1

在创建快照之前调用此方法UIElement

public static UIElement GetMeasuredAndArrangedVisual(UIElement visual)
{
    visual.Measure(new Size
    {
        Height = double.PositiveInfinity,
        Width = double.PositiveInfinity
    });

    visual.Arrange(new Rect(0, 0, visual.DesiredSize.Width, visual.DesiredSize.Height));

    visual.UpdateLayout();

    return visual;
}
于 2012-03-06T16:43:47.427 回答