任何人都可以发现我正在做的错误吗?以编程方式将子项添加到堆栈面板不起作用
下面是代码:
StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Vertical;
for (int index = _elements.Count - 1; index >= 0; index--)
{
FrameworkElement element = _elements[index];
WriteableBitmap tempBitmap = new WriteableBitmap(element, null);
Image image = new Image();
image.Source = tempBitmap;
stackPanel.Children.Add(image);
}
stackPanel.UpdateLayout();
_bitmap = new WriteableBitmap(stackPanel, null);
_bitmap.Invalidate();
正如你可以看到我创建一个临时的图像,然后将其添加到StackPanel中,然后创建一个最终WriteableBitmap的。 MYY StackPanel中的第一个孩子是身高154和第二一个就是389这条线之后:
_bitmap.Invalidate();
,当我看到PixelHeight它仅仅是389在哪里我的第一个孩子去了?
需要添加的东西,尝试显式设置高度和宽度到堆栈面板并使用它来设置'Size'和'Rect' – 2015-12-22 18:20:01