Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

drop and drag Eventhandlers are not getting called for treeviewitem with heirarchaldatatemplate in wpf

$
0
0

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="{Binding
XPath=./*}">
            <StackPanel Orientation="Horizontal">
                               
                <TextBlock Margin="5,0,0,0"
                   Text="{Binding
XPath=@Name}"

}" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate DataType="Step">
            <StackPanel Orientation="Horizontal">
                                <TextBlock Margin="5,0,0,0"
                           Text="{Binding
XPath=@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>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>