Click here to Skip to main content
15,891,774 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: ToggleButton in datagrid Pin
Jammer11-Jul-10 22:47
Jammer11-Jul-10 22:47 
AnswerRe: ToggleButton in datagrid Pin
sillvor12-Jul-10 11:56
sillvor12-Jul-10 11:56 
QuestionTab index not working properly with user controls Pin
dashingsidds10-Jul-10 2:37
dashingsidds10-Jul-10 2:37 
QuestionNo connection could be made because the target machine actively refused it Pin
Venkadeshbabu9-Jul-10 2:08
Venkadeshbabu9-Jul-10 2:08 
AnswerRe: No connection could be made because the target machine actively refused it Pin
Pete O'Hanlon9-Jul-10 2:34
mvePete O'Hanlon9-Jul-10 2:34 
AnswerRe: File Upload in Silver Light Pin
Abhinav S9-Jul-10 17:47
Abhinav S9-Jul-10 17:47 
QuestionWorking Out Which Controls are Within Points Pin
Jammer9-Jul-10 0:23
Jammer9-Jul-10 0:23 
AnswerRe: Working Out Which Controls are Within Points Pin
Pete O'Hanlon9-Jul-10 1:54
mvePete O'Hanlon9-Jul-10 1:54 
As you are aware, it can seem pretty tricky to work out what the location of a control is in WPF space because the margin relates to the parent of the control which may or may not be the window. What you could do is something like this:
private Point GetElementLocation<T>(Window window, T control) where T : UIElement
{
  GeneralTransform xform = control.TransformToAncestor(window);
  return xform.Transform(new Point(0,0));
}
This gives you the co-ordinates of the top-left of the control. From here, it's fairly simple to work out how big a control is by adding the Width and Height in, which gives you the rectangle that represents your control. Now, it's a simple matter to just check the bounds of each control and see if it falls inside your selection rectangle (note that this is a rough test only, as it really only caters for rectangular shapes - it's entirely possible that a circle doesn't fall within the bounds for instance).

Note that an alternative to TransformToAncestor is to use the following:
private Point GetElementLocation&lt;T&gt;(Window window, T control) where T : UIElement
{
  Vector vector = VisualTreeHelper.GetOffsetAt(control);
  return new Point(vector.X, vector.Y);
}

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



GeneralRe: Working Out Which Controls are Within Points Pin
Jammer9-Jul-10 2:39
Jammer9-Jul-10 2:39 
GeneralRe: Working Out Which Controls are Within Points Pin
Jammer9-Jul-10 3:37
Jammer9-Jul-10 3:37 
GeneralRe: Working Out Which Controls are Within Points Pin
Pete O'Hanlon9-Jul-10 3:50
mvePete O'Hanlon9-Jul-10 3:50 
QuestionWPF Navigation Frame Pin
Gretna7-Jul-10 22:55
Gretna7-Jul-10 22:55 
QuestionWPF : Print Page number on footer Pin
priyagee7-Jul-10 21:30
priyagee7-Jul-10 21:30 
QuestionSimple problem pre-select WPF Codeplex ComboBox item [modified] Pin
devvvy7-Jul-10 15:54
devvvy7-Jul-10 15:54 
Questionmultiple WCF client endpoints exposed as dropdown list Pin
Michael Eber7-Jul-10 13:00
Michael Eber7-Jul-10 13:00 
QuestionDomainServicess??? Pin
Chris H Developer7-Jul-10 8:32
Chris H Developer7-Jul-10 8:32 
QuestionGraphical Lasso to Select Controls Pin
Jammer7-Jul-10 6:03
Jammer7-Jul-10 6:03 
AnswerRe: Graphical Lasso to Select Controls Pin
Insincere Dave9-Jul-10 4:13
Insincere Dave9-Jul-10 4:13 
GeneralRe: Graphical Lasso to Select Controls Pin
Jammer9-Jul-10 6:12
Jammer9-Jul-10 6:12 
QuestionDrawing rubber-band lines and shapes on mouse events in WPF Pin
hamidkhan6-Jul-10 4:59
hamidkhan6-Jul-10 4:59 
AnswerRe: Drawing rubber-band lines and shapes on mouse events in WPF Pin
Abhinav S7-Jul-10 2:10
Abhinav S7-Jul-10 2:10 
QuestionWPF : Print Select Dialog in XamReportPreview Pin
priyagee6-Jul-10 3:14
priyagee6-Jul-10 3:14 
Questionhow to embeded a youtube video in a silverlight page(.xaml page) using silverlightblend 3.0. Pin
Ch.Gayatri Subudhi5-Jul-10 22:00
Ch.Gayatri Subudhi5-Jul-10 22:00 
AnswerRe: how to embeded a youtube video in a silverlight page(.xaml page) using silverlightblend 3.0. Pin
Arun Jacob5-Jul-10 22:52
Arun Jacob5-Jul-10 22:52 
GeneralRe: how to embeded a youtube video in a silverlight page(.xaml page) using silverlightblend 3.0. Pin
Ch.Gayatri Subudhi6-Jul-10 18:22
Ch.Gayatri Subudhi6-Jul-10 18:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.