Drag And Drop from UserControl

9 posts, 1 answers
  1. Paul Cook
    Paul Cook avatar
    9 posts
    Member since:
    Sep 2008

    Posted 31 Mar 2009 Link to this post

    Hi,

    I have a RadTreeView *within* a UserControl which I am using from a regular XAML Page.

    When I use "RadDragAndDropManager.SetAllowDrag(myUserControl, true);" I'm notified of the drag event successfully.

    Obviously this is a bit silly as I don't want to detect dragging the UserControl, I really want to detect dragging tree nodes. So, the question is how do I use SetAllowDrag for each tree node?

    I have exposed the node collection publicly and tried iterating through an using SetAllowDrag, but I'm not sure if this is an good  method. Also, each node is an object which isn't currently derived from DependencyObject. When I DO derive from DependencyObject I get a XAML error at runtime.

    Any ideas?

    Paul.
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 31 Mar 2009 Link to this post

    Hello Paul,

    As I understand, you are binding the TreeView. Then there is no need to iterate over the items collection. You need to set the property to the item container wrappers over your objects, which is easy with the ItemContainerStyle property of the TreeView. The property is inherited, so you need to set it only once.

    The interesting thing here is that you can set attached properties in styles:

    <nav:RadTreeView  x:Name="treeView" 
            ItemTemplate="{StaticResource myItemTemplate}">  
        <nav:RadTreeView.ItemContainerStyle> 
            <Style TargetType="nav:RadTreeViewItem">  
                <Setter  
                        Property="dragDrop:RadDragAndDropManager.AllowDrag" 
                        Value="True" /> 
            </Style> 
        </nav:RadTreeView.ItemContainerStyle> 
    </nav:RadTreeView> 

    Hopefully this will work in your scenario,

    Regards,
    Miroslav
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Paul Cook
    Paul Cook avatar
    9 posts
    Member since:
    Sep 2008

    Posted 01 Apr 2009 Link to this post

    But can this be done from Page.xaml when the RadTreeView is embedded within a user control within a different assembly?
  5. Paul Cook
    Paul Cook avatar
    9 posts
    Member since:
    Sep 2008

    Posted 02 Apr 2009 Link to this post

    Let me be a bit more descriptive:

    I have a control called CategoryTree.xaml which is located in *another assembly*. This control is structured as:

    <UserControl>
        <Grid>
            <telerik:RadTreeView>

    I can reference this assembly and I can place this control on my page, but I now need to enable draganddrop from this control to another control on my page.

    The question is how can I use RadDragAndDropManger to set CategoryTree (or, more precisley, the RadTreeView items) as the drag source? Can this even be done?

    I'm guessing I need to somehow expose the RadTreeView as a property?!? Is it a dependency property?!?! I'm coming from an ASP.NET background so I'm not yet thinking the Silverlight way yet!

    Paul.
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 03 Apr 2009 Link to this post

    Hello Paul,

    Sorry for the delayed reply!

    The appropriate Silverlight application model is a bit different than asp.net, but I am sure that you will quickly start feeling at home with it.

    Some of the differences are attached properties and routed events. Generally it is best to have DataObjects which represent your data, ViewModels which are very much alike the DataItems, but have extra logic and properties that are not part of the DataModel.

    Then the UI elements will wrap around and bind to the ViewModels.

    You indeed do not need to inherit the DependencyObject, in fact it is best not to.

    Since the RadTreeView is data bound, you can use the ItemContainerStyle to set properties to the container (the wrapping RadTreeViewItem). So could you try the suggested xaml addition for the tree view you want to make draggable:

    <nav:RadTreeView.ItemContainerStyle>    
        <Style TargetType="nav:RadTreeViewItem">     
            <Setter     
                    Property="dragDrop:RadDragAndDropManager.AllowDrag"    
                    Value="True" />    
        </Style>    
    </nav:RadTreeView.ItemContainerStyle>    
     

    This xaml sets the AllowDrag attached property to all the TreeViewItems of the TreeView.

    It this will make sure that routed events start travelling from the TreeViewItems to the application root visual and you can handle them anywhere you like, even in its parent UserControl from another assembly.

    If you need more help with this, please come back to us.

    Sincerely yours,
    Miroslav
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  7. Paul Cook
    Paul Cook avatar
    9 posts
    Member since:
    Sep 2008

    Posted 15 Apr 2009 Link to this post

    Hi Miroslav,

    I'm finally getting the hang of this. I have started out with two listboxes and can drag listitems between them having used attatched properties to hook the dragdrop functionality.

     

    The thing is that my application the treeview is in a usercontrol. How can I use attached properties to attach to tree items externally, from the page?

    eg. I need to drag items from RadTreeView below into DropTarget (another 3rd party control)

    <Page>
        <UserControl>
            <Grid>
                <telerik:RadTreeView>
            </Grid>
        </UserControl>

        <DropTarget />

    Paul.

  8. Answer
    Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 17 Apr 2009 Link to this post

    Hello Paul Cook,

    Attached, you can find en example demonstrating the structure described in your post. Actually, this is a modification of the FirstLook example from our online demos - the left DraggableListBox is separated in a standalone UserControl which is finally placed at the list box's place. In-depth information is available in the RadControls for Silverlight 2 - Drag and Drop Basics article.

    Please give it a try and let me know does it cover your needs.

    Greetings,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Sergey dsa
    Sergey dsa avatar
    3 posts
    Member since:
    Apr 2010

    Posted 17 Sep 2010 Link to this post

    Hi!
    Is there possibility to disable drag and dropping  inside (within) Silverlight RadScheduler, specifically within TimeLine Definition? I have tried that way:

    <
    Style x:Key="TimelineTimeSlotStyle" TargetType="telerikScheduler:TimeSlotItem">
    <Setter Property="telerikDragDrop:RadDragAndDropManager.AllowDrag" Value="False" />
     
    But it does not work for me..
    Thanks.
  10. Teodor
    Admin
    Teodor avatar
    501 posts

    Posted 22 Sep 2010 Link to this post

    Hi Sergey dsa,

    Please refer to the following article from our help section:
    http://www.telerik.com/help/silverlight/schedulerdraganddrop.html

    It describes how you can manipulate drag and drop of appointments within RadScheduler

    Hope this will be of use. Let us know if you need further assistance.

    All the best,
    Teodor
    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
DevCraft banner