visualtreehelper

Getting the index of the selected RadioButton in a group

瘦欲@ 提交于 2019-11-29 12:30:13
I have got a reference to a RadioButton rb1. How can I get the index of the selected RadioButton in rb1's group ? I have googled for a while but without success. Any help will be greatly appreciated If you got to this point then there is probably something wrong with your design and you should reconsider it. that being said you could traverse the visual tree and find it like this: /// Returns the first GroupBox ancester public DependencyObject FindAncestor(DependencyObject current) { current = VisualTreeHelper.GetParent(current); while (current != null) { if (current is GroupBox) { return (T

Getting the index of the selected RadioButton in a group

拜拜、爱过 提交于 2019-11-28 06:26:06
问题 I have got a reference to a RadioButton rb1. How can I get the index of the selected RadioButton in rb1's group ? I have googled for a while but without success. Any help will be greatly appreciated 回答1: If you got to this point then there is probably something wrong with your design and you should reconsider it. that being said you could traverse the visual tree and find it like this: /// Returns the first GroupBox ancester public DependencyObject FindAncestor(DependencyObject current) {

Problem with VisualTreeHelper.HitTest in WPF

自作多情 提交于 2019-11-27 07:55:59
问题 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 never hits, it should, but it doesn't. If I use the FilterCallback, I return that it hit nothing. If I let the HitTest run through the visual tree, it skips the UserControl. Here's some code: <Canvas x:Name="Container"> <UserControl> <Grid>

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