Custom Shape Container

4 posts, 1 answers
  1. Paul
    Paul avatar
    14 posts
    Member since:
    Dec 2010

    Posted 15 Jun 2015 Link to this post

    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

  2. Jakub
    Jakub avatar
    26 posts
    Member since:
    Apr 2015

    Posted 15 Jun 2015 in reply to Paul Link to this post

    Hi, 

     

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Paul
    Paul avatar
    14 posts
    Member since:
    Dec 2010

    Posted 15 Jun 2015 in reply to Jakub Link to this post

    Unfortunately that doesn't work - at runtime it still resizes if you move the children against the edges.
  5. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 16 Jun 2015 Link to this post

    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
Back to Top