R
Rolf Welskes
Hello,
because there are no managed news group for window presentation foundation
and one has told me I can use this, here my problem:
simple example:
<Window x:Class="TreeViewHitTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="354" Width="644" >
<Grid Background="LightGray">
<TreeView AllowDrop="True" Background="LightBlue"
HorizontalAlignment="Left" Margin="10,10,0,71" Name="treeView" Width="200"
PreviewMouseDown="grid01_PreviewMouseDown">
<TreeViewItem Header="aaa01"/>
<TreeViewItem Header="aaa02"/>
<TreeViewItem Header="aaa03" />
</TreeView>
<ListBox Margin="286,56,138,71" Name="lbxResult" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TreeViewHitTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public HitTestResultBehavior HitTestResultFunc(HitTestResult result)
{
DependencyObject dobj = result.VisualHit;
lbxResult.Items.Add(dobj.GetType().Name);
return HitTestResultBehavior.Continue;
}
private void grid01_PreviewMouseDown(object sender,
MouseButtonEventArgs e)
{
lbxResult.Items.Clear();
VisualTreeHelper.HitTest(treeView , null, HitTestResultFunc, new
PointHitTestParameters(e.GetPosition(treeView)));
}
}
}
So if you start the program and left click on a TreeViewItem in the
treeview, you see the hittesting starts
at TextBlock, this seems ok, but then it travers the visual tree and does
not reach each element,
ESPESPIALY I need the TreeViewItem which is clicked, but this is not in the
list of the items found hittesting.
Thank you for any help.
Rolf Welskes
because there are no managed news group for window presentation foundation
and one has told me I can use this, here my problem:
simple example:
<Window x:Class="TreeViewHitTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="354" Width="644" >
<Grid Background="LightGray">
<TreeView AllowDrop="True" Background="LightBlue"
HorizontalAlignment="Left" Margin="10,10,0,71" Name="treeView" Width="200"
PreviewMouseDown="grid01_PreviewMouseDown">
<TreeViewItem Header="aaa01"/>
<TreeViewItem Header="aaa02"/>
<TreeViewItem Header="aaa03" />
</TreeView>
<ListBox Margin="286,56,138,71" Name="lbxResult" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TreeViewHitTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public HitTestResultBehavior HitTestResultFunc(HitTestResult result)
{
DependencyObject dobj = result.VisualHit;
lbxResult.Items.Add(dobj.GetType().Name);
return HitTestResultBehavior.Continue;
}
private void grid01_PreviewMouseDown(object sender,
MouseButtonEventArgs e)
{
lbxResult.Items.Clear();
VisualTreeHelper.HitTest(treeView , null, HitTestResultFunc, new
PointHitTestParameters(e.GetPosition(treeView)));
}
}
}
So if you start the program and left click on a TreeViewItem in the
treeview, you see the hittesting starts
at TextBlock, this seems ok, but then it travers the visual tree and does
not reach each element,
ESPESPIALY I need the TreeViewItem which is clicked, but this is not in the
list of the items found hittesting.
Thank you for any help.
Rolf Welskes