This is a migrated thread and some comments may be shown as answers.

Custom Shape Container

3 Answers 201 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 15 Jun 2015, 01:26 PM

Hi

I'm trying to create a custom shape container by restyling RadDiagramContainerShape, but I'm running into a few problems relating to layout. It appears that RadDiagramContainerShape forces a specific padding between the edge and the children and moves the container if the children touch the border. It also resizes to accommodate the children.

Is there any way to hide the header, force it to not resize and allow the children to be positioned right up against the edges?

I'm trying to create a UI design tool and need a container that will allow the contained children to be position anywhere in the container.

Thanks

3 Answers, 1 is accepted

Sort by
0
Jakub
Top achievements
Rank 1
answered on 15 Jun 2015, 01:44 PM

Hi, 

 

try to set ContainerLayout property to "Fixed" it might help in first case. 

0
Paul
Top achievements
Rank 1
answered on 15 Jun 2015, 01:48 PM
Unfortunately that doesn't work - at runtime it still resizes if you move the children against the edges.
0
Accepted
Martin Ivanov
Telerik team
answered on 16 Jun 2015, 01:45 PM
Hi guys,

There no built-in mechanism for disabling of the described behavior which resize the container automatically. In order to achieve this you will need to write custom code - for example you can create a custom container shape which derives from RadDiagramContainerShape and override its CalculateContentBounds() method. You can return different bounds depending on a condition. Here is an example for this approach:
public class FixedContainer : RadDiagramContainerShape
{
    public static readonly DependencyProperty IsFixedProperty =
        DependencyProperty.Register("IsFixed", typeof(bool), typeof(FixedContainer), new PropertyMetadata(false));
 
    public bool IsFixed
    {
        get { return (bool)GetValue(IsFixedProperty); }
        set { SetValue(IsFixedProperty, value); }
    }
 
    protected override System.Windows.Rect CalculateContentBounds(System.Windows.Rect newShapeBounds)
    {      
        if (this.IsFixed)
            return this.ContentBounds;
        return base.CalculateContentBounds(newShapeBounds);
    }  
}

<telerik:RadDiagram>
    <local:FixedContainer Position="100 100" IsFixed="True">
        <telerik:RadDiagramShape Position="120 120"  />
    </local:FixedContainer>           
</telerik:RadDiagram>

About hiding the header, you can modify the template of the container shape and hide the Grid element that holds the header. Or you can override the OnApplyTemplate() method of the container shape and get, and hide the Grid in code. For your convenience I prepared a sample project demonstrating those approached. Please give them a try and let me know if they work for you.

As for the ContainerLayout property, note that this enumeration is not used in the diagram's code. Can you please tell me which version of our controls you are using and how you are using the ContainerLayout enum? Thank you for any information you can provide.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
Paul
Top achievements
Rank 1
Answers by
Jakub
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or