Questions tagged [visual-tree]
106 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
20
votes
2 answers
Binding ElementName. Does it use Visual Tree or Logical Tree
Having {Binding ElementName=foo}, will it lookup visual or logical tree?
Of logical and visual trees in WPF | Data See, Data Do
When does the logical tree matter?
When looking up a name, such as in
{Binding ElementName=Foo}, the search
walks up…

alex2k8
- 42,496
- 57
- 170
- 221
19
votes
1 answer
WPF container to turn all child controls to read-only
I would like to have a WPF container (panel, user control, etc.) that exposes a property to turn all children to read-only if set. This should pretty much be like setting a parent control to IsEnabled=false, which also disables all children. What…

user1211286
- 681
- 5
- 17
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
1 answer
Removing an item from the visual tree in a generic way
I would like to remove a FrameworkElement from the visual tree. Since the FrameworkElement has a Parent property, it would be obvious to solve this problem by removing it from there:
FrameworkElement childElement;
if(childElement != null &&…

Gergely Orosz
- 6,475
- 4
- 47
- 59
7
votes
2 answers
WPF - How to detect when new Visual child elements are added?
Based on some custom security settings, I alter window child controls to readonly and disabled. To accomplish this, I loop through child controls when the window loads.
This works just fine. 99% perfect.
In my window I have an ItemsControl whose…

Jerry Nixon
- 31,313
- 14
- 117
- 233
7
votes
1 answer
Visual Studio 2017 Live Visual Tree doesn't work
I can't enable Live Visual Tree in Visual Studio 2017 for UWP app (C#). This tool was working on VS2015, but never worked for me in VS2017. It works with no problems for my WPF projects.
I'm getting the following error message in Live Visual…

Mike Keskinov
- 11,614
- 6
- 59
- 87
6
votes
2 answers
Move a UserControl from a ContentControl to another one programmatically
In a WPF app I want to move a UserControl from a ContentControl to another one in code:
myContentControl2.Content = myUserControl;
in this case I get an error:
Specified element is already the logical child of another element. Disconnect it…

rem
- 16,745
- 37
- 112
- 180
5
votes
1 answer
Actual Visibility in WPF
In WPF an element can have a Visibility of "Visible", but not be actually visible on the screen because it's parent (or parent of parent) has Visibility of Collapsed.
I want to be able to know if a element is actually rendered on the screen,…

Chris Nicol
- 10,256
- 7
- 39
- 49
5
votes
0 answers
Concepts of Visual tree and Logical tree
I understand the concepts of Visual and logical tree but still I am not able to understand the real use and need of these. Although its not necessary to know everything about these trees but I believe it will benefit in some advanced scenarios.
I…

akjoshi
- 15,374
- 13
- 103
- 121
5
votes
4 answers
ListBoxItem.Parent returns nothing, unable to get it thru VisualTreeHelper.GetParent either
How do I extract the parent container of a ListBoxItem?
In the following example I can go till the ListBoxItem, higher than that I get Nothing:
5
votes
1 answer
wpf force to build visual tree
I have ItemsControl with Grid as ItemsPanelTemplate
…

user1308583
- 153
- 1
- 7
4
votes
4 answers
Silverlight & Visual Tree Manipulation
Now this may be more trouble than it's worth but nevertheless, it'd be really useful to me right now.
What I'd like to know is how I might go about manipulating the Silverlight visual tree at runtime. Doing simple things like adding and removing…

EightyOne Unite
- 11,665
- 14
- 79
- 105
4
votes
2 answers
WPF: In an attached property, how to wait until visual tree loaded properly?
I have an Attached Property in a WPF app.
The code below is inside the OnLoad event, but it doesn't work unless I add a hacky 500 millisecond delay in.
Is there some way to avoid this delay, and detect when the visual tree has been loaded?
private…

Contango
- 76,540
- 58
- 260
- 305
4
votes
2 answers
DataTemplate defined in XAML has null VisualTree
I'm using WPF with .NET 3.0.
I have a relatively simple DataTemplate defined as the CellTemplate for a GridView. I expect the DataTemplate's VisualTree property to contain a FrameworkElementFactory, but the property is null when I try to access it…

atoumey
- 2,536
- 2
- 20
- 16