![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 |
| | #2 (permalink) |
| Guest | 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 |
| | #3 (permalink) |
| Guest | 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 |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding edge coordinates of elements | Ofer | Avalon | 1 | 01-08-2008 10:23 AM |
| Texture Coordinates across multiple meshes | Avery Z | Avalon | 1 | 10-19-2006 07:29 PM |
| API Standards question: FrameworkElement.Focusable | Keith Patrick | Avalon | 3 | 02-27-2006 02:11 AM |
| How to draw a line without explicitly specifying its coordinates | Pascal Bourque | Avalon | 4 | 02-04-2006 03:37 AM |
| FrameworkElement overlay notification? | Jason Dolinger | Avalon | 1 | 02-02-2006 12:50 PM |