I am currently trying to Drag Drop Custom Control from List box to RadDiagram.
I am able to Drag the Custom Control (Shell) but not able to Create a Shape in RadDiagram.
Code:
Shell (Custom Control)
public class Shell : Telerik.Windows.Controls.Diagrams.RadDiagramShapeBase
{
static Shell()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Shell), new FrameworkPropertyMetadata(typeof(Shell)));
}
}
Style
<Style TargetType="{x:Type local:Shell}">
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Shell}">
<Grid Background="{TemplateBinding Background}">
<Ellipse Stroke="{TemplateBinding BorderBrush}"/>
<Ellipse Margin="13" Stroke="Black" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Drag And Drop Code
Telerik.Windows.DragDrop.DragDropManager.AddDragInitializeHandler(listBox, OnDragInitialize); (ListBox)
Telerik.Windows.DragDrop.DragDropManager.AddDropHandler(radDiagram, OnDropShape);(RadDiagram)
private void OnDropShape(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
e.Handled = true;
Shell shape = new Shell();
var rawdata= (e.Data as DataObject).GetData(typeof(Shell));
{
Shell droppedShape = rawdata as Shell;
this.radDiagram.AddShape(droppedShape);
}
}
private void OnDragInitialize(object sender,Telerik.Windows.DragDrop.DragInitializeEventArgs e)
{
e.AllowedEffects = DragDropEffects.All;
Shell draggedshape = (e.OriginalSource as ListBoxItem).Content as Shell;
e.Data = draggedshape;
}
I am able to get the dragged Shell but i don`t know how to convert the Shell object to RadDiagramShape.
Any help is appreciated!!!
I am able to Drag the Custom Control (Shell) but not able to Create a Shape in RadDiagram.
Code:
Shell (Custom Control)
public class Shell : Telerik.Windows.Controls.Diagrams.RadDiagramShapeBase
{
static Shell()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Shell), new FrameworkPropertyMetadata(typeof(Shell)));
}
}
Style
<Style TargetType="{x:Type local:Shell}">
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Shell}">
<Grid Background="{TemplateBinding Background}">
<Ellipse Stroke="{TemplateBinding BorderBrush}"/>
<Ellipse Margin="13" Stroke="Black" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Drag And Drop Code
Telerik.Windows.DragDrop.DragDropManager.AddDragInitializeHandler(listBox, OnDragInitialize); (ListBox)
Telerik.Windows.DragDrop.DragDropManager.AddDropHandler(radDiagram, OnDropShape);(RadDiagram)
private void OnDropShape(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
e.Handled = true;
Shell shape = new Shell();
var rawdata= (e.Data as DataObject).GetData(typeof(Shell));
{
Shell droppedShape = rawdata as Shell;
this.radDiagram.AddShape(droppedShape);
}
}
private void OnDragInitialize(object sender,Telerik.Windows.DragDrop.DragInitializeEventArgs e)
{
e.AllowedEffects = DragDropEffects.All;
Shell draggedshape = (e.OriginalSource as ListBoxItem).Content as Shell;
e.Data = draggedshape;
}
I am able to get the dragged Shell but i don`t know how to convert the Shell object to RadDiagramShape.
Any help is appreciated!!!