tags:

views:

28

answers:

0

Hi, I want to create a speed dial feature in WPF. I have seen that feature in browsers. where multiple page images are shown. The user can click on the pages to go to that page.

I searched in Google and found that i can do this using RenderTargetBitmap. Basically i am trying to create the image of the screen using RenderTargetBitmap and add it to the stackpanel. But i am not able to add the image to the stackpanel. Any suggestion?

 List<Visual> visualList = new List<Visual>();          
 UserControls.UserControl1 uc1 = new UserControls.UserControl1();
                            visualList.Add(uc1);
 for(int i = 0;i<=6;i++)
            {
                Image img = new Image();
                img.Source = CaptureScreen(visualList[i], 96, 96);
                img.Margin = new Thickness { Top = 2 };                   
                usingWorkaround.Children.Add(img);
            }


private static RenderTargetBitmap CaptureScreen(Visual target, double dpiX, double dpiY)
    {
        if (target == null)
        {
            return null;
        }
        Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
        //RenderTargetBitmap rtb = new RenderTargetBitmap((int)(bounds.Width * dpiX / 96.0),
        //                                                (int)(bounds.Height * dpiY / 96.0),
        //                                                dpiX,
        //                                                dpiY,
        //                                                PixelFormats.Pbgra32);
        RenderTargetBitmap rtb = new RenderTargetBitmap(596,596,dpiX,
                                                        dpiY,
                                                        PixelFormats.Pbgra32);
        DrawingVisual dv = new DrawingVisual();
        using (DrawingContext ctx = dv.RenderOpen())
        {
            VisualBrush vb = new VisualBrush(target);
            ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
        }
        rtb.Render(dv);
        return rtb;
    }