locked
How to position popup control? RRS feed

  • Question

  • Popup control have property HorizontalOffset and VerticalOffset, but this is relative to it direct parent control, for example if you put popup control insdie a Grid, these are relative position to Grid.

    But the main page may load control in many layers, such as page loading control1, control1 loading control 2,...

    Popup is always on the top for all controls. how to put popup in proper position, for example, use mouse position for popop?

     

    Tuesday, May 12, 2009 10:29 AM

Answers

  • If you want the popup window to be above a particular control (such as a mouseover tooltip), you can get the transform information from the control and insert those values into the Popup's Vertical and Horizontal offsets.

    C#:

    private void PopupOpen(object sender, MouseButtonEventArgs e)
    {
        Image visual = sender as Image;
        GeneralTransform transform = base.TransformToVisual(visual);
        Point point = transform.Transform(new Point(0.0, 0.0));
    
        PopupWindow.VerticalOffset = this.Margin.Top + Math.Abs(point.Y);
        PopupWindow.HorizontalOffset = this.Margin.Left + Math.Abs(point.X);
    
        PopupWindow.IsOpen = true;
    }
     
    Tuesday, May 12, 2009 1:22 PM

All replies

  • If you want the popup window to be above a particular control (such as a mouseover tooltip), you can get the transform information from the control and insert those values into the Popup's Vertical and Horizontal offsets.

    C#:

    private void PopupOpen(object sender, MouseButtonEventArgs e)
    {
        Image visual = sender as Image;
        GeneralTransform transform = base.TransformToVisual(visual);
        Point point = transform.Transform(new Point(0.0, 0.0));
    
        PopupWindow.VerticalOffset = this.Margin.Top + Math.Abs(point.Y);
        PopupWindow.HorizontalOffset = this.Margin.Left + Math.Abs(point.X);
    
        PopupWindow.IsOpen = true;
    }
     
    Tuesday, May 12, 2009 1:22 PM
  • Hi,

    Popup is a pretty primitive class and you'll have to start manually aligning it, position it, close & open it, etc.

    We shipped the Picker class in the Silverlight Toolkit to encapsulate all that logic.

    Please let me know If you're interested in me publishing a tutorial on my blog on how to inherit from this class.

    Sincerely,

    Tuesday, May 19, 2009 6:34 PM
  •  Yes, Please, Justin. I also want to know the solution on following situation:

    Put ChildWindow inside popup control and allow the childwindow working as normally. Thanks. 

    Wednesday, May 20, 2009 9:28 AM
  • Justin,

    I am very interested in the abstract Picker class, now a part of the Silverlight Toolkit.  Is there any way you could post a minimal sample to help guide us in how to use it?

    Thanks,
    Jim McCurdy

    Tuesday, May 26, 2009 11:26 PM