MakubeX

导航

WPFUIElement的Background的问题

 

 

  <Border Name="border" CornerRadius="15"  Margin="5">
                        <Border.Background>
                            <VisualBrush>
                                <VisualBrush.Visual>
                                    <Image Name="img"  Stretch="UniformToFill" Grid.Row="1" />
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </Border.Background>
                    </Border>

以上代码 经过 下面的  打印之后  img的Source 改变值之后也不可变了..  

   RenderTargetBitmap bitmap = new RenderTargetBitmap((int)grid.ActualWidth, (int)grid.ActualHeight, 96, 96, PixelFormats.Pbgra32);
            bitmap.Render(grid);

            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

            PngBitmapEncoder encode = new PngBitmapEncoder();
            encode.Frames.Add(BitmapFrame.Create(bitmap));
            MemoryStream ms = new MemoryStream();
            encode.Save(ms);
            bitmap.Clear();
            drawimg = System.Drawing.Image.FromStream(ms);
            //rect = new System.Drawing.Rectangle(0, 0, (int)grid.ActualWidth, (int)grid.ActualHeight);
            pd.Print();

 

需要用   border.InvalidateVisual();  重新计算 UI... 原因未知,先保留

posted on 2013-08-06 20:01  Makubex  阅读(484)  评论(0编辑  收藏  举报