1

我必须打印一个显示的 TreeView。

将根 TreeViewItem 渲染为位图,为我提供了整个(甚至不可见节点)树的图像。然后我将位图拆分为要打印的“页面”。渲染代码:

m_Bitmap = new RenderTargetBitmap((int)l_RootTreeViewItem.ActualHeightDesiredSize.Width,
                                  (int)l_RootTreeViewItem.ActualHeight, 96, 96,
                                  PixelFormats.Pbgra32);

m_Bitmap.Render(l_RootTreeViewItem);

适用于小型树木。如果树很大,RenderTargetBitmap会导致“Out Of Memory”异常。

因此,我们的想法是只渲染部分视觉效果以避免内存问题。一种渲染方法,我可以在其中选择要渲染的视觉部分是完美的......

m_Bitmap.Render(l_RootTreeViewItem, xOffset, yOffset, width, height);

……但不存在。有什么办法吗?

4

1 回答 1

1

我会做什么:

  • 创建一个VisualBrush你的l_RootTreeViewItem
  • 创建一个Rectangle并将视觉画笔分配给Fill属性
  • 播放VisualBrush.ViewboxVisualBrush.Viewport渲染我感兴趣的树视图部分
  • RenderTargetBitmap.Render需要时在我的矩形上使用

编辑

解决方案 2

  • 放入l_RootTreeViewItem画布
  • ClipToBounds画布的属性设置为true
  • 使用Canvas.Width,Canvas.Height属性和Canvas.Left,Canvas.Top附加属性只显示一部分TreeViewItem
  • PrintDialog.PrintVisual根据需要在画布上使用。

    <Canvas Width="300" Height="300" ClipToBounds="True">
        <TreeViewItem Canvas.Left="-200" Canvas.Top="-100">
            ...
        </TreeViewItem>
    </Canvas>
    
于 2012-04-25T07:45:44.253 回答