I have a ListBox and RadGridView and I'm trying to implement Drag And Drop between list items and grid rows and vice versa.
This is for testing purposes and I'm trying to test raising and capturing Drop and DragCompleted events on all RadGridView parts.
Everything works fine except drop to a Header Row of a RadGridView. Drop and DragCompleted is not raised and also DragVisual shows that you can't drop to a Header Row of a RadGridView. I guess this is a default behavior of RadGridView and I would like to ask if there is any way or workaround how to drop to a Header Row of a RadGridView? I need this feature for a WPF application in my work.
here is my xaml
and here is my code behind
thanks
This is for testing purposes and I'm trying to test raising and capturing Drop and DragCompleted events on all RadGridView parts.
Everything works fine except drop to a Header Row of a RadGridView. Drop and DragCompleted is not raised and also DragVisual shows that you can't drop to a Header Row of a RadGridView. I guess this is a default behavior of RadGridView and I would like to ask if there is any way or workaround how to drop to a Header Row of a RadGridView? I need this feature for a WPF application in my work.
here is my xaml
<Window x:Class="DragDropManager.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" > <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <Style TargetType="ListBoxItem"> <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True"></Setter> </Style> <DataTemplate x:Key="ApplicationTemplate"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding IconPath}"/> <TextBlock Margin="5" Text="{Binding Name}" VerticalAlignment="Center"></TextBlock> </StackPanel> </DataTemplate> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <ListBox x:Name="ApplicationList" ItemTemplate="{StaticResource ApplicationTemplate}" AllowDrop="True"/> <telerik:RadGridView Grid.Column="1" AllowDrop="True" x:Name="MyGrid"> <telerik:RadGridView.RowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" /> </Style> </telerik:RadGridView.RowStyle> </telerik:RadGridView> </Grid></Window>and here is my code behind
public partial class MainWindow : Window{ public MainWindow() { InitializeComponent(); ApplicationList.ItemsSource = ApplicationInfo.GenerateApplicationInfos(); MyGrid.ItemsSource = new ObservableCollection<ApplicationInfo>(); Telerik.Windows.DragDrop.DragDropManager.AddDragInitializeHandler(ApplicationList, OnDragInitialize); Telerik.Windows.DragDrop.DragDropManager.AddDragInitializeHandler(MyGrid, OnDragInitialize); Telerik.Windows.DragDrop.DragDropManager.AddGiveFeedbackHandler(ApplicationList, OnGiveFeedback); Telerik.Windows.DragDrop.DragDropManager.AddGiveFeedbackHandler(MyGrid, OnGiveFeedback); Telerik.Windows.DragDrop.DragDropManager.AddDragDropCompletedHandler(ApplicationList, OnDragCompleted); Telerik.Windows.DragDrop.DragDropManager.AddDragDropCompletedHandler(MyGrid, OnDragCompleted2); Telerik.Windows.DragDrop.DragDropManager.AddDropHandler(ApplicationList, OnDrop); Telerik.Windows.DragDrop.DragDropManager.AddDropHandler(MyGrid, OnDrop2); } private void OnDragInitialize(object sender, DragInitializeEventArgs args) { args.AllowedEffects = DragDropEffects.All; var payload = DragDropPayloadManager.GeneratePayload(null); var data = ((FrameworkElement)args.OriginalSource).DataContext; payload.SetData("DragData", data); args.Data = payload; args.DragVisual = new DragVisual() { Content = data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate }; args.DragVisualOffset = args.RelativeStartPoint; args.Handled = true; } private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args) { args.SetCursor(Cursors.Arrow); args.Handled = true; } private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args) { var data = ((DataObject)args.Data).GetData("DragData"); ((IList)(sender as ListBox).ItemsSource).Add(data); } public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args) { var data = DragDropPayloadManager.GetDataFromObject(args.Data, "DragData"); ((IList)(sender as ListBox).ItemsSource).Remove(data); } private void OnDrop2(object sender, Telerik.Windows.DragDrop.DragEventArgs args) { var data = ((DataObject)args.Data).GetData("DragData"); ((IList)(sender as RadGridView).ItemsSource).Add(data); } public void OnDragCompleted2(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args) { var data = DragDropPayloadManager.GetDataFromObject(args.Data, "DragData"); ((IList)(sender as RadGridView).ItemsSource).Remove(data); }}thanks