.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > Creating thumbnails of a grid/WrapPanel or other UIElement in WPF?
Ask a questionAsk a question
 

AnswerCreating thumbnails of a grid/WrapPanel or other UIElement in WPF?

  • Thursday, July 13, 2006 9:36 AMOlle Gustafsson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hey!
    Im working on a new menu for our application. When a new "work area" is opened (everyting in one application window), I'd like to put a small instance icon in the top of the screen so that the user, if opening more than one instance, easily can navigate through the instances.

    I have managed to get this to work. Now I'm trying to fix a nice feature for the instance icons. If the user hovers with the mouse over the instance icon I'd like a screenshot thumbnail of that work area to be shown in the tooltip of that instance. Kind of like the new menubar in Vista.

    Does anyone know what to do? Please see code example at end of message

    I have tried to make a copy of the work area, scale it down and then view it in the thumbnail. But I can't even make a copy of the work area (it's a wrappanel).

    The other thing Iäve tried is to make a bitmap respresentation of the Wrappanel, but I haven't found the right classes/methods for that either.

    Please help me!



    Kind regards

    Mr Olle Gustafsson
    Stockholm, Sweden



            void InstanceMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
            {
                StackPanel tooltipcontent;
                Button instance = sender as Button;
                object[] instancedata = instance.Tag as object[];
                Grid visualObject = instancedata[1] as Grid;
              
                if (instance.ToolTip == null)
                {
                    ToolTip tt = new ToolTip();
                    tt.Background = Brushes.Transparent;
                    LinearGradientBrush tooltipborderbrush = new LinearGradientBrush(Brushes.Black.Color, Brushes.Transparent.Color, new Point(0.5, 0.8), new Point(0.5, 0));
                    tt.BorderThickness = new Thickness(1);
                    tt.BorderBrush = Brushes.Transparent; // tooltipborderbrush;
                    tooltipcontent = new StackPanel();

                    LinearGradientBrush brush = new LinearGradientBrush(Brushes.SteelBlue.Color, Brushes.Transparent.Color, 50);
                    tooltipcontent.Background = brush;
                   
                    // HERE i'd like to get a screenshot of the visualObject!!!

                    Label lbl = new Label();
                    lbl.Background = Brushes.Transparent;
                    lbl.BorderThickness = new Thickness(0);
                    lbl.Content = "VisualObject Name: Instance Name";

                    Label lbl2 = new Label();
                    lbl2.Background = Brushes.Transparent;
                    lbl2.BorderThickness = new Thickness(0);
                    lbl2.Content = "This is the long description of this instance. "; //Hardly Anyone know exactly what it does, or where it comes from. But my guess is that it is alien.";
                    tooltipcontent.Children.Add(lbl);
                    tooltipcontent.Children.Add(lbl2);
                    tt.Content = tooltipcontent;
                    instance.ToolTip = tt;
                }
                e.Handled = true;
            }

Answers

  • Thursday, July 13, 2006 11:02 AMOlle Gustafsson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Thanks for your reply!
    Very simple solution and it seems like it's no time consuming at all.

    Here is the code that solved it:

    VisualBrush vb = new VisualBrush(visualObject as Visual);

    vb.Viewport = new Rect(new Size(160, 80));
    vb.Viewbox = new Rect(new Size(160, 80));

    Rectangle myRectangle = new Rectangle();
    myRectangle.Width = 160;
    myRectangle.Height = 80;
    myRectangle.Stroke = Brushes.Transparent;
    myRectangle.Margin = new Thickness(0, 0, 0, 0);
    myRectangle.Fill = vb;




    Thanks!

    Olle Gustafsson

All Replies

  • Thursday, July 13, 2006 9:44 AMIanGMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Have you tried VisualBrush? That lets you paint any shape with the contents of another Visual.

    It sounds like it should be ideal for what you're trying to do. Unless I've misunderstood your goal.

  • Thursday, July 13, 2006 11:02 AMOlle Gustafsson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Thanks for your reply!
    Very simple solution and it seems like it's no time consuming at all.

    Here is the code that solved it:

    VisualBrush vb = new VisualBrush(visualObject as Visual);

    vb.Viewport = new Rect(new Size(160, 80));
    vb.Viewbox = new Rect(new Size(160, 80));

    Rectangle myRectangle = new Rectangle();
    myRectangle.Width = 160;
    myRectangle.Height = 80;
    myRectangle.Stroke = Brushes.Transparent;
    myRectangle.Margin = new Thickness(0, 0, 0, 0);
    myRectangle.Fill = vb;




    Thanks!

    Olle Gustafsson