TreeView dragcue

2 posts, 0 answers
  1. Kelley Wong
    Kelley Wong avatar
    21 posts
    Member since:
    May 2010

    Posted 15 Jun 2012 Link to this post

    when i use silverlight 4,the dragcue works well
    now i upgrade to silverlight 5 , it displays abnormally
    i create a test project ,and the code as follows

    <UserControl x:Class="RadControlsSilverlightApp1.MainPage"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 mc:Ignorable="d"
                 d:DesignWidth="640"
                 d:DesignHeight="480">
     
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="2*" />
            </Grid.ColumnDefinitions>
     
            <telerik:RadTreeView x:Name="countryTree">
                <telerik:RadTreeViewItem IsExpanded="True"
                                         Header="Country">
                    <telerik:RadTreeViewItem Header="Russia" />
                    <telerik:RadTreeViewItem Header="Czech Republic" />
                    <telerik:RadTreeViewItem Header="Poland" />
                    <telerik:RadTreeViewItem Header="Greece" />
                    <telerik:RadTreeViewItem Header="Germany" />
                    <telerik:RadTreeViewItem Header="Portugal" />
                    <telerik:RadTreeViewItem Header="Denmark" />
                    <telerik:RadTreeViewItem Header="Netherlands" />
                    <telerik:RadTreeViewItem Header="Spain" />
                    <telerik:RadTreeViewItem Header="Croatia" />
                    <telerik:RadTreeViewItem Header="Italy" />
                    <telerik:RadTreeViewItem Header="Ireland" />
                    <telerik:RadTreeViewItem Header="Ukraine" />
                    <telerik:RadTreeViewItem Header="England" />
                    <telerik:RadTreeViewItem Header="France" />
                    <telerik:RadTreeViewItem Header="Sweden" />
     
                </telerik:RadTreeViewItem>
            </telerik:RadTreeView>
     
            <Canvas Grid.Column="1"
                    x:Name="canvas" />
        </Grid>
     
    </UserControl>

    using System.Windows.Controls;
    using Telerik.Windows.Controls.DragDrop;
     
    namespace RadControlsSilverlightApp1
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                RadDragAndDropManager.AddDropInfoHandler(canvas, OnDropInfo);
                RadDragAndDropManager.AddDropQueryHandler(canvas, OnDropQuery);
     
                RadDragAndDropManager.SetAllowDrop(canvas, true);
     
                RadDragAndDropManager.AddDragInfoHandler(countryTree, OnDragInfo);
                RadDragAndDropManager.AddDragQueryHandler(countryTree, OnDragQuery);
                RadDragAndDropManager.SetAllowDrag(countryTree, true);
     
            }
     
            private void OnDropInfo(object sender, DragDropEventArgs e)
            {
                var droppablePanel = e.Options.Destination;
                if (e.Options.Status == DragStatus.DropComplete && droppablePanel is Canvas)
                {
     
                }
            }
     
            private void OnDropQuery(object sender, DragDropQueryEventArgs e)
            {
                var droppablePanel = e.Options.Destination;
                if (e.Options.Status == DragStatus.DropDestinationQuery && droppablePanel is Canvas)
                {
                    e.QueryResult = true;
                    e.Handled = true;
                }
            }
     
            private void OnDragInfo(object sender, DragDropEventArgs e)
            {
                if (e.Options.Status == DragStatus.DragComplete)
                {
     
                }
            }
     
            private void OnDragQuery(object sender, DragDropQueryEventArgs e)
            {
                if (e.Options.Status == DragStatus.DragQuery)
                {
                    #region Silverlight 5
                    if (e.Options.Source is Telerik.Windows.Controls.RadTreeView)
                    {
                        Telerik.Windows.Controls.RadTreeView draggedTreeView = e.Options.Source as Telerik.Windows.Controls.RadTreeView;
     
                        if (draggedTreeView.SelectedItem != null)
                        {
                            Telerik.Windows.Controls.RadTreeViewItem draggedTreeViewItem = draggedTreeView.SelectedItem as Telerik.Windows.Controls.RadTreeViewItem;
     
                            if (draggedTreeViewItem != null)
                            {
                                e.Options.DragCue = draggedTreeViewItem.Header;
                            }
                        }
                    }
                    #endregion
     
                    #region Silverlight 4
                    else if (e.Options.Source is Telerik.Windows.Controls.RadTreeViewItem)
                    {
                        Telerik.Windows.Controls.RadTreeViewItem draggedTreeViewItem = e.Options.Source as Telerik.Windows.Controls.RadTreeViewItem;
                        if (draggedTreeViewItem != null)
                        {
                            e.Options.DragCue = draggedTreeViewItem.Header;
                        }
                    }
                    #endregion
                }
     
                e.QueryResult = true;
                e.Handled = true;
            }
     
        }
    }

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Jun 2012 Link to this post

    Hi Kelley,

     This is issue has nothing to do with Silverlight version rather than the RadTreeView/RadDragDropManager internal logic.. Actually the DND Manager somehow uses the position of the RadTreeView for the start position of the DragCue. Do you need to set  AllowDrag on RadTreeView  ? I made the following changes to your code :
    1) No need to set allow drag of the treeview. You always drag treeviewitems.

    //RadDragAndDropManager.SetAllowDrag(countryTree, true);
    2)Instead, set allow drag to every item
    private void countryTree_ItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
            {
                RadDragAndDropManager.SetAllowDrag(e.PreparedItem, true);
            }
    3)The source is now always a radtreeviewitem:
    private void OnDragQuery(object sender, DragDropQueryEventArgs e)
           {
               if (e.Options.Status == DragStatus.DragQuery)
               {
                   if (e.Options.Source is Telerik.Windows.Controls.RadTreeViewItem)
                   {
                       Telerik.Windows.Controls.RadTreeViewItem draggedTreeViewItem = e.Options.Source as Telerik.Windows.Controls.RadTreeViewItem;
                       if (draggedTreeViewItem != null)
                       {
                           e.Options.DragCue = draggedTreeViewItem.Header;
                       }
                   }
               }
               e.QueryResult = true;
               e.Handled = true;
           }
    Hope this re-factoring is suitable for you.
    Regards,
    Petar Mladenov
    the Telerik team

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

  3. DevCraft banner
Back to Top