Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
55 changes: 2 additions & 53 deletions controls/dragdropmanager/behaviors/customizingdragvisual.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,7 @@ The interface exposes the following members.
This section shows how to create a custom drag visual provider that allows you to define a custom DataTemplate and use it with any DragDropBehavior implementation.

__Example 1: Creating a custom drag visual provider__
```C#
public class CustomDragVisualProvider : DependencyObject, IDragVisualProvider
{
public static readonly DependencyProperty DraggedItemTemplateProperty =
DependencyProperty.Register(
"DraggedItemTemplate",
typeof(DataTemplate),
typeof(CustomDragVisualProvider),
new PropertyMetadata(null));

public DataTemplate DraggedItemTemplate
{
get { return (DataTemplate)GetValue(DraggedItemTemplateProperty); }
set { SetValue(DraggedItemTemplateProperty, value); }
}

public FrameworkElement CreateDragVisual(DragVisualProviderState state)
{
var visual = new DragVisual();
visual.Content = state.DraggedItems.OfType<object>().FirstOrDefault();
visual.ContentTemplate = this.DraggedItemTemplate;
return visual;
}

public Point GetDragVisualOffset(DragVisualProviderState state)
{
return state.RelativeStartPoint;
}

public bool UseDefaultCursors { get; set; }
}
```
<snippet id='dragdropmanager-behaviors-customizingdragvisual-example_1_creating_a_custom_drag_visual_provider-cs' />

>important This approach is applicable for all controls that use a DragDropBehavior. For example, ScheduleViewDragDropBehavior, or a custom implementation of the DragDropBehavior class.

Expand All @@ -63,27 +32,7 @@ __Example 1: Creating a custom drag visual provider__
This section shows how to setup a ListBoxDragDropBehavior that will use the custom drag visual provider implemented in the previous section.

__Example 2: Using the custom drag visual provider__
```XAML
<ListBox ItemsSource="{Binding MyItems}" DisplayMemberPath="Name">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
</Style>
</ListBox.ItemContainerStyle>
<telerik:ListBoxDragDrop.Behavior>
<telerik:ListBoxDragDropBehavior />
</telerik:ListBoxDragDrop.Behavior>
<telerik:ListBoxDragDrop.DragVisualProvider>
<local:CustomDragVisualProvider>
<local:CustomDragVisualProvider.DraggedItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Background="#823DBF" Padding="15" Foreground="White"/>
</DataTemplate>
</local:CustomDragVisualProvider.DraggedItemTemplate>
</local:CustomDragVisualProvider>
</telerik:ListBoxDragDrop.DragVisualProvider>
</ListBox>
```
<snippet id='dragdropmanager-behaviors-customizingdragvisual-example_2_using_the_custom_drag_visual_provider-xaml' />

#### Figure 1: Custom drag visual provider
![dragdropmanager customizingdragvisual](images/dragdropmanager-customizingdragvisual-0.png)
Loading