繁体   English   中英

RenderTargetBitmap不尊重ColumnDefinitions宽度

[英]RenderTargetBitmap does not respect ColumnDefinitions width

我需要使用一些隐藏列创建Grid的快照(通过设置它的ColumnDefinition.Width = 0)。

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

我试过像这个片段的方法

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

在创建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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM