Click here to Skip to main content
15,914,225 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: silverlight4 tools for visual studio 2010 fails with the following error… HELP! Pin
Tiju John12-Jul-10 18:55
Tiju John12-Jul-10 18:55 
AnswerRe: silverlight4 tools for visual studio 2010 fails with the following error… HELP! Pin
Kunal Chowdhury «IN»12-Jul-10 19:36
professionalKunal Chowdhury «IN»12-Jul-10 19:36 
GeneralRe: silverlight4 tools for visual studio 2010 fails with the following error… HELP! Pin
Tiju John16-Jul-10 5:36
Tiju John16-Jul-10 5:36 
QuestionWant to learn Silverlight from scratch in ASP.Net Pin
Amit Spadez11-Jul-10 21:38
professionalAmit Spadez11-Jul-10 21:38 
AnswerRe: Want to learn Silverlight from scratch in ASP.Net Pin
Abhinav S11-Jul-10 22:06
Abhinav S11-Jul-10 22:06 
GeneralRe: Want to learn Silverlight from scratch in ASP.Net Pin
Amit Spadez11-Jul-10 22:13
professionalAmit Spadez11-Jul-10 22:13 
AnswerRe: Want to learn Silverlight from scratch in ASP.Net Pin
Abhinav S11-Jul-10 23:08
Abhinav S11-Jul-10 23:08 
AnswerRe: Want to learn Silverlight from scratch in ASP.Net Pin
Kunal Chowdhury «IN»12-Jul-10 17:23
professionalKunal Chowdhury «IN»12-Jul-10 17:23 
QuestionComboBox Items (Binding?) Pin
seblake11-Jul-10 13:31
seblake11-Jul-10 13:31 
AnswerRe: ComboBox Items (Binding?) Pin
Jammer11-Jul-10 22:43
Jammer11-Jul-10 22:43 
GeneralRe: ComboBox Items (Binding?) Pin
seblake13-Jul-10 16:58
seblake13-Jul-10 16:58 
GeneralRe: ComboBox Items (Binding?) Pin
Jammer14-Jul-10 1:36
Jammer14-Jul-10 1:36 
GeneralRe: ComboBox Items (Binding?) Pin
seblake14-Jul-10 8:03
seblake14-Jul-10 8:03 
GeneralRe: ComboBox Items (Binding?) Pin
Jammer14-Jul-10 23:37
Jammer14-Jul-10 23:37 
QuestionToggleButton in datagrid Pin
Chris Hotchkiss11-Jul-10 6:28
Chris Hotchkiss11-Jul-10 6:28 
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 

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.