How to customize the DragVisualProvider
In RadListBox it is possible to enrich the drag-drop functionality of the control by creating a custom DragVisualProvider or using one of the built-in DragVisualProviders. More information about the built-in DragVisualProviders could be found here.
Custom DragVisualProvider
The next example will demonstrate the how to create a custom DragVisualProvider in order to change its Foreground, Background, BorderBrush and Template.
Before proceeding with this example you should get familiar with Drag and Drop: Overview, Implicit Styles and Binding To Object.
-
First you will need to create a Country class with the necessary properties:
Country class creation
-
Next you should create a Countries collection in your ViewModel and populate it with some sample data:
ViewModel declaration_
-
In the App.xaml file merge the necessary ResourceDictionary for the RadListBox control based on the theme you are using. This example uses the Office_Black theme:
Merging the necessary ResourceDictionary
-
Next you will need to create a Style in the same file that targets ListBoxDragVisual and set its Foreground, Background, BorderBrush and Template properties:
Style targeting ListBoxDragVisual
You can find the entire ListBoxDragVisual Template code in each specific theme for the RadListBox control.The custom DragVisualStyle must be created in the App.xaml file as the DragVisualProvider is placed inside of another visual tree and cannot be targeted from the /Window where RadListBox is placed.
-
Finally you will need to declare the RadListBox control. The xaml of the control should look like this:
RadListBox declaration
Find a runnable project of the previous example in the WPF Samples GitHub repository.
The next screenshots show the final result: