小编Vin*_*ins的帖子

元素的布局测量覆盖不应返回 NaN 值作为其 DesiredSize

Measure当我尝试调用动态计算的大小并将其传递给该方法时,我遇到了类似的问题:

元素“System.Windows.Controls.StackPanel”的布局测量覆盖不应返回 NaN 值作为其 DesiredSize。

我正在尝试动态创建一个 StackPanel 并打印它。这是我的代码:

StackPanel printPanel = new StackPanel();

PrintableArea.Children.Remove(ChartBorder);
printPanel.Children.Add(ChartBorder);

//Get selected printer capabilities
System.Printing.PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);

//Get scale of the print wrt to screen of visual
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / printPanel.ActualWidth, capabilities.PageImageableArea.ExtentHeight / printPanel.ActualHeight);

//Transform the Visual to scale
printPanel.LayoutTransform = new ScaleTransform(scale, scale);

//Get the size of the printer page
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

//Update the layout of the visual to the printer page size.
printPanel.Measure(sz);
printPanel.Arrange(new Rect(new …
Run Code Online (Sandbox Code Playgroud)

.net printing wpf

5
推荐指数
1
解决办法
4949
查看次数

标签 统计

.net ×1

printing ×1

wpf ×1