0

Not sure why this is not working. In my WPF I defined an event for a DROP event in the ItemContainerStyle and the event handler in the code behind. But when I drag the file I get a circle with a diagnonal line through it. Here is the WPF code

<TreeView ItemsSource="{Binding Roots}" Name="Tree" Margin="0,22,0,0" Background="AliceBlue">
<TreeView.ItemContainerStyle>
                <!--      This Style binds a TreeViewItem to a TreeViewItemViewModel.      -->
                <Style TargetType="{x:Type TreeViewItem}">
                    <EventSetter Event="Drop" Handler="treeView_Drop"></EventSetter>
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Setter Property="ContextMenu" Value="{Binding ContextMenu}" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

etc.

The code behind is just a skeleton now. I am happy just to take a break point

 private void treeView_Drop(object sender, DragEventArgs e)
    {
        try
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
               // just a skeleton for now
            }
        }
        catch (Exception ex)
        {

        }
    }

All ideas are welcome and thanks

2 Answers 2

1

You should set the AllowDrop property of the TreeViewItem class:

<Setter Property="AllowDrop" Value="True" />
1
  • I tried that and it did not work. I read that you cannot drop files on a application that runs in admin mode which mine does. If that is the case, I'll have to redesign. Is this really true. If so, why? Security issues? Anyway, thanks for your response.
    – Rick
    Mar 19, 2014 at 13:51
0

OK, Last night I found out some good information that might be helpful to someone else. It is true that I could not drop a file from windows explorer on to my tree view node because I run in admin mode.

I then created a button, ran a windows dialog box from the click event and after navigating to a file was able to successfully drop it on the tree view node.

In fact, I got two events to fire. The first was the event, I set up on the treeview node itself in the ItemContainerStyle. The other event was for the stackpanel implementation in the HeirarchicalDataTemplate.

I was pleasantly surprised to see it it work. (How often does that happen?) But now I realize I still have not tested it as a deployment (darn)

Anyway, Oliver was the only one to apply so I am going to give him some kudo's right here - Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.