Hi,
I am trying to drop shape into a container shape, but the shape is not displaying inside the container. Could anyone help me solve it? Here is my code.
EventManager.RegisterClassHandler(
typeof
(RadDiagramContainerShape), RadDiagramShape.DropEvent,
new
System.Windows.DragEventHandler(OnDrop));
private
void
OnDrop(
object
sender, System.Windows.DragEventArgs e)
{
e.Handled =
true
;
if
((e.Data
as
DataObject)?.GetData(
typeof
(DragObject))
is
DragObject dragObject)
{
var itemBase = (ActivityBase)Activator.CreateInstance(dragObject.ContentType);
var p = e.GetPosition(MainDiagram);
var shape= createDiagramShape(itemBase);
RadDiagramContainerShape target = (sender
as
RadDiagramContainerShape);
target.Items.Add(shape);
}
}
private
RadDiagramShape createDiagramShape(ActivityBase activity)
{
var shape =
new
RadDiagramShape
{
Content = activity,
BorderThickness =
new
Thickness(1),
UseGlidingConnector =
true
,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
VerticalContentAlignment = VerticalAlignment.Stretch,
DataContext = activity,
UseDefaultConnectors =
false
,
IsRotationEnabled =
false
,
Background =
new
SolidColorBrush(Color.FromArgb(255, 255, 255, 255)),
GlidingStyle = GlidingStyle.Rectangle
};
var outconnector =
new
InOutConnector
{
Offset =
new
Point(1, 0.2),
Direction = eDirection.drOut,
Name =
"out"
+ DateTime.Now.Millisecond
};
shape.Connectors.Add(outconnector);
var inconnector =
new
InOutConnector
{
Offset =
new
Point(0, 0.2),
Direction = eDirection.drIn,
Name =
"in"
+ DateTime.Now.Millisecond,
};
shape.Connectors.Add(inconnector);
return
shape;
}
The following function to drop shape inside the diagram works.
private
void
OnDropShape(
object
sender, DragEventArgs e)
{
e.Handled =
true
;
if
((e.Data
as
DataObject)?.GetData(
typeof
(DragObject))
is
DragObject dragObject)
{
var itemBase = (ActivityBase) Activator.CreateInstance(dragObject.ContentType);
var p = e.GetPosition(MainDiagram);
var shape = createDiagramShape(itemBase);
MainDiagram.AddShape(shape, MainDiagram.GetTransformedPoint(p));
_mainViewModel.ShapeCollection = MainDiagram.Shapes;
_mainViewModel.SelectedActivity = calendar.DataContext
as
ActivityBase;
}
}
Thanks,
Rahul