Custom DragActionContent for TreeViewDragCue with TreeView

5 posts, 0 answers
  1. Vasile
    Vasile avatar
    33 posts
    Member since:
    Dec 2010

    Posted 02 Aug 2011 Link to this post

    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.

     

  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 05 Aug 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Vasile
    Vasile avatar
    33 posts
    Member since:
    Dec 2010

    Posted 05 Aug 2011 Link to this post

    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

  5. Vasile
    Vasile avatar
    33 posts
    Member since:
    Dec 2010

    Posted 08 Aug 2011 Link to this post

    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
  6. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

Back to Top
DevCraft banner