DragDrop Hosted in Windows Forms

8 posts, 0 answers
  1. Boots
    Boots avatar
    81 posts
    Member since:
    Dec 2008

    Posted 19 Nov 2009 Link to this post

    Hello,

    I'm having trouble with the RadDragAndDropManager when the UserControl that is using it is being hosted inside of a Windows Form. I made a quick example.

    <UserControl x:Class="DragAndDropTest.simple" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"
        <UserControl.Resources> 
            <Style TargetType="StackPanel"
                <Setter Property="dragDrop:RadDragAndDropManager.AllowDrop" Value="True" /> 
            </Style> 
            <Style TargetType="Label"
                <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" /> 
            </Style> 
        </UserControl.Resources> 
        <Grid> 
            <Grid.ColumnDefinitions> 
                <ColumnDefinition /> 
                <ColumnDefinition /> 
            </Grid.ColumnDefinitions> 
            <StackPanel 
                Name="Stack1" 
                Grid.Column="0"
                <Label Name="lbl1" Background="Green" /> 
            </StackPanel> 
            <StackPanel  
                Name="Stack2" 
                Grid.Column="1"
                <Label Name="lbl2" Background="Red" /> 
            </StackPanel> 
        </Grid> 
    </UserControl> 
     


    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Data; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Imaging; 
    using System.Windows.Navigation; 
    using System.Windows.Shapes; 
    using Telerik.Windows.Controls.DragDrop; 
     
    namespace DragAndDropTest 
        /// <summary> 
        /// Interaction logic for simple.xaml 
        /// </summary> 
        public partial class simple : UserControl 
        { 
            public simple() 
            { 
                InitializeComponent(); 
     
                RadDragAndDropManager.AddDragInfoHandler(lbl1, OnDragInfo); 
                RadDragAndDropManager.AddDragQueryHandler(lbl1, OnDragQuery); 
     
                RadDragAndDropManager.AddDragInfoHandler(lbl2, OnDragInfo); 
                RadDragAndDropManager.AddDragQueryHandler(lbl2, OnDragQuery); 
     
                RadDragAndDropManager.AddDropInfoHandler(Stack1, OnDropInfo); 
                RadDragAndDropManager.AddDropQueryHandler(Stack1, OnDropQuery); 
     
                RadDragAndDropManager.AddDropInfoHandler(Stack2, OnDropInfo); 
                RadDragAndDropManager.AddDropQueryHandler(Stack2, OnDropQuery); 
            } 
     
            private void OnDropQuery(object sender, DragDropQueryEventArgs e) 
            { 
                e.QueryResult = true
                e.Handled = true
            } 
     
            private void OnDropInfo(object sender, DragDropEventArgs e) 
            { 
                if (e.Options.Status == DragStatus.DropComplete) 
                { 
                    ((e.Options.Source as Label).Parent as StackPanel).Children.Remove(e.Options.Source); 
                    (sender as StackPanel).Children.Add(e.Options.Source); 
                } 
            } 
     
            private void OnDragInfo(object sender, DragDropEventArgs e) 
            { 
                Label item = sender as Label; 
                if (e.Options.Status == DragStatus.DragInProgress) 
                { 
                        ContentControl cue = new ContentControl(); 
                        cue.Content = new Label() { Background = item.Background }; 
     
                        e.Options.DragCue = cue; 
                        e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue(); 
                } 
            } 
     
            private void OnDragQuery(object sender, DragDropQueryEventArgs e) 
            { 
                e.Options.Payload = sender; 
                e.QueryResult = true
                e.Handled = true
            } 
        } 
     


    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; 
     
    namespace DragAndDropTest  
        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
                elementHost1.Child = new simple(); 
            } 
        } 

    seems to work fine inside of a wpf Window but not a Form.
    Any ideas on what I'm doing wrong?

    Thanks much,
    ~Boots
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 23 Nov 2009 Link to this post

    Hello Ben,

    You are not doing anything wrong. This is an issue we are aware of a fix will be available in one of the internal builds after our Service Pack 1. Thank you, however, for reporting it and if you have additional questions, let me know. Also, I will make sure to update you once the fix is available.

    Best wishes,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. nbahl
    nbahl avatar
    25 posts
    Member since:
    Feb 2007

    Posted 11 Jan 2010 Link to this post

    Hello,
    Do you know when the fix for this will be available?  I see there is an internal build from 12/19 available but I don't see this fix in the release notes.

    Thanks,
    Nate
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 14 Jan 2010 Link to this post

    Hello nbahl,

    Indeed the fix for this issue is not available yet, it will not be included in the SP2 release coming out shortly.

    It is scheduled for the Q1 release and will probably appear earlier in one of the weekly Internal Builds.

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Franziska
    Franziska avatar
    29 posts
    Member since:
    Dec 2009

    Posted 26 Jan 2010 Link to this post

    Hello Miroslav

    In my case, drag&drop doesn't work on a wpf window opened from Windows Form. Is this the same issue?
    On my window there is a docking area with some DockingPanes and in one of these DockingPanes there is a TreeView with IsDragDropEnabled="True".
    I have tried it with the trial versions 2009.3 1314 and 2009.3 1322.

    With the latest trial version 2009.3 1322 visual studio 2008 seems to have problems, because the desinger throws unhandled exceptions when opening .xaml files:
    Cannot create instance of 'GenericTheme' defined in assembly 'Microsoft.Windows.Design.Interaction, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Exception has been thrown by the target of an invocation.
    Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.Media.Brush'.

    When I use the 2009.3 1314 binaries, the designer has no problems.

    Best Regards,
    Franziska


  7. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 28 Jan 2010 Link to this post

    Hello Franziska Rohr,

    We apologize for the caused inconvenience.Thank you for reporting this issue it is already added in our to do list and will be fixed as soon as possible for some of the next releases.

    Sincerely yours,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Ralf Markus
    Ralf Markus avatar
    8 posts
    Member since:
    Mar 2009

    Posted 22 Jul 2010 Link to this post

    Hi,

    I am facing the same issues with Version 2010.2
    Any word on when this will be fixed?

    Regards
  9. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 27 Jul 2010 Link to this post

    Hello Ralf,

    There have been improvements in this area, for example the Boot's example now works. There are some cases where the DragDrop is not fully featured yet - for example the TreeView only drops items inside other items but not before/after them.

    I am attaching a project with this thread' example.

    What scenario does not work in your case?

    Kind regards,
    Miroslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready