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

Double-fired OnDrop for listbox inside RadTileView

0 Answers 46 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Wenrong
Top achievements
Rank 1
Wenrong asked on 05 Jun 2012, 09:43 AM
When the list box lives inside a RadTileView, the OnDrop event will get fired twice with the same parameters.
<telerik:RadTileView>
    <telerik:RadTileViewItem>
 
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.Resources>
                <Style TargetType="ListViewItem">
                    <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"></Setter>
                </Style>
                <DataTemplate x:Key="ApplicationTemplate">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="5" Text="{Binding Name}" VerticalAlignment="Center"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <ListView x:Name="ApplicationList" ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/>
            <ListView x:Name="MyAppList" Background="Gray" Grid.Column="1" 
            ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/>
        </Grid>
    </telerik:RadTileViewItem>
</telerik:RadTileView>


public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        ObservableCollection<Item> items = new ObservableCollection<Item>();
        for (int i = 1; i <= 10; i++)
            items.Add(new Item() { Name = string.Format("item {0}", i) });
        ApplicationList.ItemsSource = items;
        MyAppList.ItemsSource = new ObservableCollection<Item>();
 
        DragDropManager.AddDragInitializeHandler(ApplicationList, OnDragInitialize);
        DragDropManager.AddDragInitializeHandler(MyAppList, OnDragInitialize);
        DragDropManager.AddGiveFeedbackHandler(ApplicationList, OnGiveFeedback);
        DragDropManager.AddGiveFeedbackHandler(MyAppList, OnGiveFeedback);
        DragDropManager.AddDragDropCompletedHandler(ApplicationList, OnDragCompleted);
        DragDropManager.AddDragDropCompletedHandler(MyAppList, OnDragCompleted);
        DragDropManager.AddDropHandler(ApplicationList, OnDrop);
        DragDropManager.AddDropHandler(MyAppList, OnDrop);
    }
 
    private void OnDragInitialize(object sender, DragInitializeEventArgs args)
    {
        args.AllowedEffects = DragDropEffects.Move;
        //args.AllowedEffects = DragDropEffects.All;
        args.Data = ((FrameworkElement)args.OriginalSource).DataContext;
        args.DragVisual = new ContentControl { Content = args.Data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate };
    }
 
    private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args)
    {
        System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnGiveFeedback sender={1}", DateTime.Now, sender));
        args.SetCursor(Cursors.Arrow);
        args.Handled = true;
    }
 
    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {
        System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnDrop sender={1}", DateTime.Now, sender));
        ((IList)(sender as ListBox).ItemsSource).Add(((DataObject)args.Data).GetData(typeof(Item)));
    }
 
    public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args)
    {
        System.Diagnostics.Trace.WriteLine(string.Format("{0} - OnDragCompleted sender={1}", DateTime.Now, sender));
        ((IList)(sender as ListBox).ItemsSource).Remove(args.Data);
    }
}
 
public class Item
{
    public string Name { get; set; }
}

No answers yet. Maybe you can help?

Tags
DragAndDrop
Asked by
Wenrong
Top achievements
Rank 1
Share this question
or