Can i restrict the children of a RadDiagramContainerShape so they cant leave it?
2 Answers, 1 is accepted
0
Francois
Telerik team
answered on 28 Nov 2012, 12:04 PM
Andrew,
it all depends on what you want. You will find a working solution below but it doesn't answer what happens when the user resizes a shape, how will a shape initially get into the container and so on. A solution embracing all this (and potentially other business related constraints) would demand a custom container based on the RadDiagramShapeBase class and would in essence be a completely different thing than the default container we shipped. In addition, the selection and resizing adorner is currently not OK and unless that code is customized as well you need to disable the manipulation adorner. In any case, have a look at the code and see if this helps you to move onwards to what you aim for.
protected override void OnPositionChanged(Point oldPosition, Point newPosition)
{
if (this.ParentContainer != null)
{
var innnerRect = new Rect(this.ParentContainer.ActualBounds.TopLeft, new Point(this.ParentContainer.ActualBounds.BottomRight.X - this.ActualBounds.Width, this.ParentContainer.ActualBounds.BottomRight.Y - this.ActualBounds.Height));
if (innnerRect.Contains(newPosition)) base.OnPositionChanged(oldPosition, newPosition);
If you are ok with the Shapes inside not being able to be moved, then you can just set the isDraggable to false on the shapes inside the Container and that took care of it for me.