Questions tagged [visualtreehelper]

92 questions
37
votes
3 answers

WPF Get Element(s) under mouse

Is there a way with WPF to get an array of elements under the mouse on a MouseMove event?
NotDan
  • 31,709
  • 36
  • 116
  • 156
18
votes
2 answers

Why click tree throws 'System.Windows.Documents.Run' is not a Visual or Visual3D' InvalidOperationException?

Sometimes right-clicking treeviewitem results unhandled InvalidOperationException. In code behind I select the right clicked row: static TreeViewItem VisualUpwardSearch(DependencyObject source) { while (source != null && !(source is…
char m
  • 7,840
  • 14
  • 68
  • 117
13
votes
2 answers

Why does the Parent property of a container of an ItemsControl return null and not the Panel it sits on?

This one has me stumped. We have a custom ItemsControl which uses both custom containers as well as a custom panel as its ItemsHost. Now the panel has some metrics that the containers need for rendering purposes. Since they are direct children of…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
10
votes
3 answers

How can I unit test something that uses VisualTreeHelper?

I have this static helper function: public static DependencyObject GetParentObject(DependencyObject child) { if (child == null) return null; ContentElement contentElement = child as ContentElement; if (contentElement…
Scott Whitlock
  • 13,739
  • 7
  • 65
  • 114
7
votes
2 answers

What is the Silverlight's FindElementsInHostCoordinates equivalent in WPF?

I would like to perform a rectangual hit test on WPF Canvas component in order to get Controls that are overlapped by a Rectangle framework element. I found a Silverlight's VisualTreeHelper.FindElementsInHostCoordinates method, but apparently it's…
Darius
  • 524
  • 1
  • 5
  • 11
6
votes
1 answer

VisualTreeHelper.GetChildren does not find children of TabItem

I have the following C# code to find children of a DepedendencyObject: public static IEnumerable FindVisualChildren(DependencyObject parent) where T : DependencyObject { int childrenCount =…
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185
5
votes
2 answers

WPF RibbonComboBox Height

Ok, I would have thought this was a simple question, but apparently it's got me confused. When I try to set the height of my RibbonComboBox, it's not moving actual size of it, just the box that surrounds it. Here is my XAML:
ErocM
  • 4,505
  • 24
  • 94
  • 161
5
votes
1 answer

FindElementsInHostCoordinates Relative To Control Space Not Entire Page

I'm using the VisualTreeHelper method FindElementsInHostCoordinates to find a ListBoxItem at the given X and Y location. However, X and Y value appear to be related to points in the entire page not just the ListBox I'm interested in (even though…
beaudetious
  • 2,354
  • 3
  • 36
  • 60
4
votes
2 answers

FrameworkElement.Parent and VisualtreeHelper.GetParent behaves differently

In a WP7 app, I used FrameworkElement.Parent recursively to determine whether a specific element is inside of another element. But it does not always work correctly. Then I changed my code to use VisualtreeHelper.GetParent method recursively, and it…
4
votes
2 answers

Problem with VisualTreeHelper.HitTest in WPF

I'm trying to hit-test a bunch of UserControls on a Canvas. I don't want the HitTest() to walk the whole way through the visual tree, so I'm using the FilterCallback to make sure I only hit-test the UserControl. My problem is that the UserControl…
Chris Nicol
  • 10,256
  • 7
  • 39
  • 49
4
votes
2 answers

Getting the Logical UIElement under the mouse in WPF

It seems that all of the way of retrieving an element under the Mouse relates to Visual Hit testing. Is there some mechanism that I'm missing which would allow me to grab the actual UIElement that represents the current visual tree that the HitTest…
tronious
  • 1,547
  • 2
  • 28
  • 45
3
votes
0 answers

Curious whether there is another way to validate all TextBoxes in a ListView

Here is what i have....shown is part of the ListView. What currently happens is this: User clicks on New button to create a new row. User may or may not enter info into the contained TextBoxes/Comboboxes prior to clicking the Save button. When…
MikeC
  • 284
  • 1
  • 3
  • 14
3
votes
2 answers

How to access new visual tree when WPF TabControl SelectedItem changes

Considering an already loaded and rendered TabControl with three tabs, with selected tab being index 1 (the middle one): Tab 1: Has one TextBox Tab 2: Has two TextBoxes Tab 3: Has three TextBoxes If I iterate through the selectedItem's visual tree…
VOliveira
  • 133
  • 1
  • 1
  • 6
3
votes
1 answer

WPF find element with VisualTreeHelper vertical and horizontal

What is the easiest way, to search vertically and horizontally in the visual tree? For example I want to find a control which is not in the list of parents from the control, which starts the search. Here is a simple example (every box represents…
BendEg
  • 20,098
  • 17
  • 57
  • 131
1
2 3 4 5 6 7