This is a migrated thread and some comments may be shown as answers.

Custom DragActionContent for TreeViewDragCue with TreeView

4 Answers 89 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Vasile
Top achievements
Rank 1
Vasile asked on 02 Aug 2011, 10:38 PM
Dear Telerik team,

I want to accomplish the following scenario:
I am developing a MVVM + PRISM + RIA application, and there are many views in a shell, I can drag around various entities between different controls (RadGridView, RadTreeView, ListBox).
I have customized the TreeViewDragCue to display the items I am dragging depending by their type, using a template selector. I also use a view model for the TreeViewDragCue instance and I use binding for some of the properties in the MVVM spirit.

Sample:
Binding hint = new Binding("Hint");
hint.Source = 
treeViewCueModel;
hint.Mode = 
BindingMode.OneWay;
BindingOperations.SetBinding(treeViewCue,
TreeViewDragCue.DragActionContentProperty, hint);
Binding possibleIcon =
new 
Binding("PossibleIcon");
possibleIcon.Source = 
treeViewCueModel;
possibleIcon.Mode = 
BindingMode.OneWay;
BindingOperations.SetBinding(treeViewCue, 
TreeViewDragCue.DropPossibleIconProperty, possibleIcon);

 


My problem now is related to the DragActionContentProperty, when I drag the TreeViewDragCue over grid or list, my Hint from the view model is properly displayed. However when I drag it over RadTreeView seems that the RadTreeView override the DragActionContent that I provide via binding from the Hint property of the viewmodel.
Instead of my "smart" message which is built contextually based on the tree item I am hovering and based on the content I am dragging, I ge a generic "Drop in" or "Drop after" or "Drop before", if I check the CallStack I see that the RadTreeView sets this in the DragActionContent property of the TreeViewDragCue.

I am using also a template for the DragActionContent

treeViewCue.DragActionContentTemplate = 
TemplateProvider.Resources["HintTemplate"] as DataTemplate;

where the template itself is defined like this:

<DataTemplate x:Key="HintTemplate">
<TextBlock Text="{Binding}" 
Margin="5" FontStyle="Italic" MaxWidth="200" TextWrapping="Wrap">
</
TextBlock>
</DataTemplate>

Is there a way to tell RadTreeView not to override the DragActionContent I am providing to the TreeViewDragCue via binding?
Can you recommend a solution for what I want to accomplish?

Thank you,
Vasile M.

 

4 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 05 Aug 2011, 02:23 PM
Hi Vasile,

Our TreeView control overrides the DragCue property of the DragDropEventArgs.Options object like this:
treeCue.DragTooltipContent = TreeViewDragCue.GetNonVisualRepresentation(destinationItem);
treeCue.DragTooltipContentTemplate = this.GetDragTooltipTemplateFromItem(destinationItem);
treeCue.DragActionContent = this.GetDragActionText(destinationItem);
treeCue.DragActionContentTemplate = null;

Where the treeCue variable is the e.Options.DragCue object that is passed to the DropInfoEvent of the RadDragAndDropManager.

The upper code is executed inside DropInfoEvent handler at the TreeView level. Actually you are able to attach custom event handler to this event and explicitly change the values inside DragCue.

Unfortunately you should do this manually and could not prevent the TreeView from setting them unless you handle the DropInfoEvent ar TreeViewItem level (before the event is bubbled up to the TreeView). But in that case you should implement the drag and drop functionality by yourself.

Finally I'm attaching a project that shows how you could manually override the changes done by the TreeView control.

All the best,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Vasile
Top achievements
Rank 1
answered on 05 Aug 2011, 02:54 PM

Thank you Hristo,

I will check your suggestion in the "real" project in couple of hours, for now I just checked your sample. If I understand it well then I can just force an update of the binding in OnTreeViewDropInfo instead of

cue.DragActionContent = "Custom Content: ";

I could use something like this:

cue.GetBindingExpression(TreeViewDragCue.DragActionContentProperty).UpdateSource();

this shall reset the cue properties with the ones from my view model that I use with the cue.
I will confirm later if this works

Vasile

0
Vasile
Top achievements
Rank 1
answered on 08 Aug 2011, 06:46 PM
Hello Hristo,

Finaly I managed to come to a conclusion, I spent some time until I figure out that my BindingExpression are gone, the tree view overriden them when assigned values to the cue properties, updating Bindings will not work, instead of this I had to rebind the cue to model, that worked.

Another solution I investigated, I observed also that if I set e.Handled = true in my event handler then the cue properties will not be overriden by the tree view, however the disadvantage of this is that also the style of the hovered item, will not be changed to illustarte that a drop is possible, so using e.Handled = true this is not really a viable solution.

Thank you,

Vasile
0
Hristo
Telerik team
answered on 10 Aug 2011, 08:13 AM
Hi Vasile,

Indeed, the TreeView just sets the DragActionContent property and the bindings are lost. At that point you should recreate the binding by yourself or set the required value for that property (you should consider which one is better because during the next drag/drop operation the binding will be lost again). This is really a drawback of the design of the TreeView and I shall consider some improvements in that functionality.

Your second solution is based on the routed events architecture. So when you handle the DropInfoEvent the treeview does not receive that event and the drag and drop functionality is incomplete. I would not recommend yo that approach, but I see that you found it by yourself.

Please let us know if you need further details or have other concerns.

Best wishes,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
DragAndDrop
Asked by
Vasile
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Vasile
Top achievements
Rank 1
Share this question
or