![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | How to get the coordinates of a FrameworkElement? In my continuing series of questions for the day, is there a way to get the coordinates of a FrameworkElement (assuming it is somewhat rectangular in shape?). There is a method Visual.getContentBounds(), which returns you the bounding Rect, but it's unfortunately an internal method. I'd assume other people would like to do this as well? I basically have a layered Grid AND Canvas. There are FrameworkElements layed out in the Grid, and when they are moused over I need to display some things somewhere in the region above them, and I'm choosing to layout those out in the Canvas. Thanks, any ideas? Jason |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to get the coordinates of a FrameworkElement? You can use VisualHelper.GetContentBounds to get the same rectangle. But, that rectangle is relative to the parent element. To get screen coordinates you would need to walk up the element tree converting the original rectangle as you go. You can do this until you get to an element with the same coordinates as your canvas. I have had problems with the Visual method that transforms a point from one coordinate space to another. Getting the transform of each visual in the tree and transforming one at a time seems to work more reliably in current CTPs. Michael "Jason Dolinger" <jdolinger@lab49.com> wrote in message news:uxlaiQgIGHA.312@TK2MSFTNGP09.phx.gbl... > In my continuing series of questions for the day, is there a way to get > the coordinates of a FrameworkElement (assuming it is somewhat rectangular > in shape?). There is a method Visual.getContentBounds(), which returns > you the bounding Rect, but it's unfortunately an internal method. > > I'd assume other people would like to do this as well? I basically have a > layered Grid AND Canvas. There are FrameworkElements layed out in the > Grid, and when they are moused over I need to display some things > somewhere in the region above them, and I'm choosing to layout those out > in the Canvas. > > Thanks, any ideas? > > Jason |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to get the coordinates of a FrameworkElement? I did this and it makes a little caption move left <--> right just above my FE according to the mouse's X position. Just hook it up to the FE's that you want to add this behavior to. I'm not sure if this is what you were looking for... I don't know what you meant by "the coordinates of a FrameworkElement". I assumed that you meant the top left corner of its bounding rect. private void OnMouseMove( object sender, MouseEventArgs args ) { // get mouse position relative to window. Point windowOffset = args.GetPosition( this ); // get mouse position relative to "sender" in the grid Point elementOffset = args.GetPosition( (FrameworkElement)sender ); // calculate the difference between the two Vector offset = windowOffset - elementOffset; // create a new element and position it on the canvas above "sender" TextBlock text = new TextBlock(); text.Text = "Caption"; text.SetValue( Canvas.LeftProperty, windowOffset.X ); // put it at mouse's x position text.SetValue( Canvas.TopProperty, offset.Y - 30 ); // 30px margin above "sender" // replace the old caption with the new one canvas.Children.Clear(); canvas.Children.Add( text ); } -- Bob Brown [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights. "Jason Dolinger" <jdolinger@lab49.com> wrote in message news:uxlaiQgIGHA.312@TK2MSFTNGP09.phx.gbl... > In my continuing series of questions for the day, is there a way to get > the coordinates of a FrameworkElement (assuming it is somewhat rectangular > in shape?). There is a method Visual.getContentBounds(), which returns > you the bounding Rect, but it's unfortunately an internal method. > > I'd assume other people would like to do this as well? I basically have a > layered Grid AND Canvas. There are FrameworkElements layed out in the > Grid, and when they are moused over I need to display some things > somewhere in the region above them, and I'm choosing to layout those out > in the Canvas. > > Thanks, any ideas? > > Jason |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Store Program Coordinates | .NET General | |||