Disable auto resize in RadDiagramContainerShape

6 posts, 0 answers
  1. Jawahar
    Jawahar avatar
    4 posts
    Member since:
    Mar 2011

    Posted 19 Nov 2013 Link to this post

    HI there,

    I am using RadDiagram, where I will have two container shapes (RadDiagramContainerShape) Front and Rear. User will choose a device and drop it into the front/rear block, so a diagram shape will be created and added into front/rear block. But once I added, the parent container shape resized even I added a shape with same width of parent.

    How to disable the auto resizing of parent container shape.

    Regards,
    Jawahar
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 22 Nov 2013 Link to this post

    Hello Jawahar,
    The auto resizing is build in the RadDiagramContainers but with Q3 2013 we released a couple of virtual methods(CalculateShapeBounds, CalculateContentBounds and CalculateMinShapeBounds) that you can override and change the default container behavior.
    I've attached a sample project with very simple implementation of fixed container - turned off the container resizing and overrode the CalculateContentBounds so that it doesn't auto resize on item drop.
    I hope I was able to help you and if you have more questions please feel free to ask.

    Regards,
    Zarko
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Elango
    Elango avatar
    2 posts
    Member since:
    May 2015

    Posted 20 Nov 2015 in reply to Zarko Link to this post

    Hi

    How do we disable auto resize in MVVM scenario?  I have a Container class that derives from ContainerNodeViewModelBase<object> and I want to disable auto resize when another element is dropped in this container.

    Regards,
    Elango

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 24 Nov 2015 Link to this post

    Hello Elango,

    Тhe same approach as the one explained in the Zarko's reply can be used also in an MVVM scenario. Basically, you can create a custom container shape that derives from the RadDiagramContainerShape class and override its CalculateContentBounds() method.
    public class FixedContainer : RadDiagramContainerShape
    {
        protected override System.Windows.Rect CalculateContentBounds(System.Windows.Rect newShapeBounds)
        {
            return this.ContentBounds;
        }
    }
    However, in order to use this container in an MVVM scenario you will also need to create a custom diagram and override its GetShapeContainerForItemOverride() method. You can find an example that demonstrates such scenario in the Create Custom Shape help article.

    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
  6. Elango
    Elango avatar
    2 posts
    Member since:
    May 2015

    Posted 08 Dec 2015 in reply to Martin Link to this post

    Hello Martin,

     Thanks for the response.  Sorry as I couldn't check this immediately.  I created a custom diagram class as you mentioned.  When I try to drag and drop a container element (from toolbox) to the diagram I am getting the following error

     'FixedContainer' TargetType does not match type of element 'RadDiagramContainerShape'.

    This occurs in the AddNode method in GraphSource class.

    Note: GraphSource is my custom class derived from SerializableGraphSourceBase<NodeViewModelBase, Link>

  7. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 11 Dec 2015 Link to this post

    Hi Elango,

    The described exception is thrown because the ContainerShapeStyle of the diagram targets the FixedContainer shape. This still is applied in code by the diagram to all container shapes when they are added. On the other hand the shape dropped from the toolbox is of type RadDiagramContainerShape. In other words a Style that targets FixedContainer is applied on an element of type RadDiagramContainerShape which is not allowed by the WPF framework and an exception is thrown.

    To resolve this error you can populate the toolbox with custom items and add the FixedContainer as a shape of the container toolbox item. This way when you drop it, the correct container will be added in the diagram and the exception won't be thrown.

    I hope this helps.

    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
UI for WPF is Visual Studio 2017 Ready