or
<
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
>
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);
}
}
<
UserControl.Resources
>
<
DataTemplate
x:Key
=
"SelectionBoxTemplate"
>
<
TextBlock
Text
=
"{Binding Code}"
FontWeight
=
"Regular"
/>
</
DataTemplate
>
</
UserControl.Resources
>
<
telerik:RadComboBox
x:Name
=
"RegionComboBox"
Grid.Column
=
"2"
Margin
=
"2"
ClearSelectionButtonContent
=
"Clear"
ClearSelectionButtonVisibility
=
"Visible"
DisplayMemberPath
=
"Code"
ItemsSource
=
"{Binding Regions}"
SelectedValue="{Binding Region,
Mode
=
TwoWay
}"
SelectedValuePath
=
"Code"
SelectionBoxTemplate
=
"{StaticResource SelectionBoxTemplate}"
/>