visual-tree

Move a UserControl from a ContentControl to another one programmatically

烈酒焚心 提交于 2019-12-03 07:53:41
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 first. In a ControlControl class description I can see a RemoveVisualChild method , but when I try to use it in code I get an Unknown method error myContentControl1.RemoveVisualChild(myUserControl);//here I get an "Unknown method" error Where am I wrong? How to move a UserControl from a ContentControl to another one in code-behind? Set myContentControl1

WPF container to turn all child controls to read-only

你说的曾经没有我的故事 提交于 2019-12-03 07:07:29
问题 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 children and which of their properties should be considered is fixed (e.g. TextBox.ReadOnly, DataGrid.ReadOnly, ...). I have tried to create such a control, which essentially iterates all children of the visual tree (recursively) and deals with the

WPF container to turn all child controls to read-only

浪子不回头ぞ 提交于 2019-12-02 20:42:22
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 children and which of their properties should be considered is fixed (e.g. TextBox.ReadOnly, DataGrid.ReadOnly, ...). I have tried to create such a control, which essentially iterates all children of the visual tree (recursively) and deals with the controls accordingly. This works fine, except for the case where further changes would affect the visual

Is there a way to move controls in the visual tree? (WPF)

☆樱花仙子☆ 提交于 2019-12-02 05:46:52
问题 I want to relocate some controls from one part in the visual tree to another. can I do this? and direction or hint on how to? 回答1: Simply remove the control from its parent, and then add it to the new parent. 回答2: Yes, you can use Insert, this way you are able to choose exactly where its index is in the visual tree. 来源: https://stackoverflow.com/questions/1074922/is-there-a-way-to-move-controls-in-the-visual-tree-wpf

How to accessing Elements in XAML DataTemplate Listview without interacting with it

青春壹個敷衍的年華 提交于 2019-12-01 12:10:21
I have a C# Store App and using DataTemplate Selectors to determine which type of Template to use in a ListView Control bound to an Array. Because it is templated, I cannot assign a dynamic x:Name to each ListView Row. I need to be able to access the listview rows by Index and set the Visibility of them to On or Off. I have tried things like this, but the .ItemContainerGenerator .ContainerFromItem(item); return null and I get a Nullable exception every time: How do I access a control inside a XAML DataTemplate? After doing some research, it appears that the above solution only works if I touch

How to accessing Elements in XAML DataTemplate Listview without interacting with it

南楼画角 提交于 2019-12-01 10:29:46
问题 I have a C# Store App and using DataTemplate Selectors to determine which type of Template to use in a ListView Control bound to an Array. Because it is templated, I cannot assign a dynamic x:Name to each ListView Row. I need to be able to access the listview rows by Index and set the Visibility of them to On or Off. I have tried things like this, but the .ItemContainerGenerator .ContainerFromItem(item); return null and I get a Nullable exception every time: How do I access a control inside a

Binding ElementName. Does it use Visual Tree or Logical Tree

旧街凉风 提交于 2019-11-27 11:57:15
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 the ancestry looking for a name scope, again just as it does for inheritable properties. ElementName binding in Silverlight via Attached Behaviours In order to enable this, WPF provides ElementName and RelativeSource bindings, giving you a powerful mechanism for locating other elements within your visual tree to bind to EDIT: It looks like the Logical

Binding ElementName. Does it use Visual Tree or Logical Tree

对着背影说爱祢 提交于 2019-11-26 15:48:59
问题 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 the ancestry looking for a name scope, again just as it does for inheritable properties. ElementName binding in Silverlight via Attached Behaviours In order to enable this, WPF provides ElementName and RelativeSource bindings, giving you a powerful

WPF Get Element(s) under mouse

风流意气都作罢 提交于 2019-11-26 03:59:31
问题 Is there a way with WPF to get an array of elements under the mouse on a MouseMove event? 回答1: From "WPF Unleashed", page 383: Visual hit testing can inform you about all Visual s that intersect a location, [...] you must use [...] the [VisualTreeHelper.]HitTest method that accepts a HitTestResultCallback delegate. Before this version of HitTest returns, the delegate is invoked once for each relevant Visual , starting from the topmost and ending at the bottommost. The signature of such a