Dragging contents of DataTemplate

3 posts, 0 answers
  1. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 01 Sep 2011 Link to this post

    I might be trying to do something that we can do but what I would like to do is attached a dragdrop manager to the contents of a datatemplate i display from an autocomplete box

    I have the following code

    <sdk:AutoCompleteBox KeyDown="searchbox_KeyDown"  telerik:StyleManager.Theme="Metro"  Height="24" HorizontalAlignment="Stretch"  Name="searchbox" BorderThickness="0" VerticalAlignment="Center"
                          VerticalContentAlignment="Center" FontSize="14" FilterMode="Contains" Margin="10,2" ValueMemberBinding="{Binding Path=Code}"
                <StackPanel Orientation="Vertical">
                    <TextBlock Width="100" telerikDragDrop:RadDragAndDropManager.AllowDrag="True"  telerikDragDrop:RadDragAndDropManager.DragQuery="TextBlock_DragQuery"  FontSize="15" FontWeight="Bold" Text="{Binding Path=Code}" Foreground="{StaticResource AccentBrush}">                                    
                    <TextBlock Width="100" FontSize="10" Text="{Binding Path=Desc}" />

    Which i though would let me drag the contents of the textblock but i get the following error

    Error 28 The property 'DragQuery' does not exist on the type 'TextBlock' in the XML namespace 'clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls'. D:\Development\UKI\trunk\iLaboratory\Views\iLaboratory.Common.Views\Controls\Menu.xaml 56 112 iLaboratory.Common.Views

    I've tried replacing the textblock with a rad control and I still get a similar message

    Can somebody advise what I'm doing wrong?

    Many thanks

  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 03 Sep 2011 Link to this post

    Hello Cameron ,

    The reason for getting the error message is that you are trying to set an event handler the way attached properties are usually set.

    Silverlight contrary to WPF does not support setting attached events in XAML .

    The solution would be to set this in code .

    For examle  - handle the loaded event ..
    <TextBlock Width="100"

    and in the loaded event handler -- subscribe to the drag event :
    private void TextBlock_Loaded(object sender, RoutedEventArgs e)
        ((TextBlock)sender).AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(TextBlock_DragQuery), true);
    * Please add using Telerik.Windows.Controls to your .cs file. in order to get access to the Telerik Addhandler extension method.

    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 05 Sep 2011 Link to this post

    I knew it had to be something simple

    Works a treat.

    Many thanks
Back to Top