Hello,
I have created a TreeView with a custom HierarchicalDataTemplate to display my items on the tree.
The items are being displayed just fine but I can't get the events of TreeViewItem to fire when something happens (like dragging, dropping etc). I only manage to get the MouseMove event to work when I try to drag and drop but even then the event handlers are not getting fired.
When I don't bind the items on the tree with my custom nodes then the events fire fine (i.e. I create some sample TreeViewItems).
Here is my xaml implementation of the TreeView
<HierarchicalDataTemplate DataType="Procedure"
ItemsSource="{BindingXPath=./*}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,0,0"
Text="{BindingXPath=@Name}"
}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="Step">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,0,0"
Text="{BindingXPath=@Name}"/>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="OptimizationSet"
ItemsSource="{Binding XPath=./*}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,0,0" Text="OptimizationSet" />
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView Name="tv"
ItemsSource="{Binding CollectionSource,Mode=TwoWay}" SelectedValuePath="{Binding SelectedStep,Mode=TwoWay}" AllowDrop="True">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="TreeViewItem.DragOver" Handler="treeView_DragOver"/>
<EventSetter Event="TreeViewItem.Drop" Handler="treeView_Drop"/>
<EventSetter Event="TreeViewItem.MouseMove" Handler="treeView_MouseMove"/>
<EventSetter Event="TreeViewItem.MouseDown" Handler="treeView_MouseDown"/>
<Setter Property="IsExpanded" Value="True" />
<Setter Property="AllowDrop" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</Grid>