[英]How to create dynamic ColumnDefinitions with relative width values?
[英]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.