This is a migrated thread and some comments may be shown as answers.

Dragging contents of DataTemplate

2 Answers 92 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Cameron Molyneux
Top achievements
Rank 1
Cameron Molyneux asked on 01 Sep 2011, 06:38 AM

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}"
                       >
    <sdk:AutoCompleteBox.ItemTemplate>
         <DataTemplate>
            <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>
                <TextBlock Width="100" FontSize="10" Text="{Binding Path=Desc}" />
            </StackPanel>
        </DataTemplate>
    </sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>


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 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 03 Sep 2011, 09:32 AM
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"
                                   telerik:RadDragAndDropManager.AllowDrag="True"
                                   Loaded="TextBlock_Loaded"

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.


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

0
Cameron Molyneux
Top achievements
Rank 1
answered on 05 Sep 2011, 07:40 AM
I knew it had to be something simple

Works a treat.

Many thanks
Tags
DragAndDrop
Asked by
Cameron Molyneux
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Cameron Molyneux
Top achievements
Rank 1
Share this question
or