tags:

views:

51

answers:

1

Hi I am trying to get the screen rectangle of a wpf button so that i can highlight it.

I use this to achieve the same:

AutomationPeer theBtnPeer = createPeerForElement(btn); Rect rect = theBtnPeer.GetBoundingScreenRectangle();

This works fine and give me the right rectangle.

However.. if the button is not currently visible then I invoke the BringIntoView() on this btn which successfully brings this button into view however when I call the GetBoundingSCreenRectangle() on it again . it gives me the same old value that was there before I invoked BringIntoView().

How do I get the new bounding rectangle of this button?

Thanks

+1  A: 

You can get the height and width of the rectangle through the ActualHeight and ActualWidth properties.

The coordinates in the window will depend on the type of the layout control that the button is in.

If your goal is to hightlight, I suggest another route: change the template of the button to include a highlight rectangle, invisible by default, with a trigger to make it visible if some condition is met.

Or using Visual States, have highlighted and not-highlighted states, with a transition that makes the highlight rectangle visible.

Timores
Thanks for the reply.and sorry about the poor formatting..It seems like I can not press {ENTER}to get to the new line. Its not only highlighting that i want to do .. i am actually intrested in getting the correct onscreen coordinate for some other functionality also.What confuses me is why the code, AutomationPeer theBtnPeer = createPeerForElement(btn); theBtnPeer.GetBoundingRectangle(); is not giving the correct rectangle after scrolling. Thanks.
Rahul
As HTML, simple carriage returns are ignored, but a second one will do the trick (I edited the question). Have you tried recursively getting the bounding rectangle of the visual tree, going upwards ? GetBoundingRectangle _may_ return the coordinates within the parent, which would implying getting its bounds and so on.
Timores