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

Layout and AutoFit once diagram has loaded

10 Answers 314 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
kilhoffer
Top achievements
Rank 1
kilhoffer asked on 21 Feb 2012, 08:15 AM
I created a layout algorithm similar to what's used in the OrgChart example. I call .Layout on it when the window hosting the diagram resizes and also call AutoFit on the diagram. Works perfectly once the window is resized. The problem I'm having, however, is that when the window first loads, the shapes are all stacked in the upper left corner. When is the proper time to run the same algorithm to get an initial layout and auto fit? Is there an event we can hook when the diagram is ready for layout?

10 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 21 Feb 2012, 08:32 AM
Hello Anthony,

 In our Org example we're doing this as you said on size changed event. 

private void Diagram_SizeChanged(object sender, SizeChangedEventArgs e)
{
    this.orgLayoutAlgorithm.Layout(this.diagram1);
    this.diagram1.AutoFit();
}

And it works as expected. Actually you only need to wait for the shapes be measured and have proper sizes. Which in fact should be ready if you hook the RadDiagram.SizeChanged event. Please let me know if it's not. One not very good solution is to delay the layout using Dispatcher, but I think you should be ok with the SizeChanged event.

All the best,
Miro Miroslavov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
kilhoffer
Top achievements
Rank 1
answered on 24 Feb 2012, 06:17 AM
Diagram.SizeChanged does not always achieve this. In my application, the SizeChanged fires before data is bound to diagram. I need a way to perform this layout after data has been bound and the control has been updated with the items. SizeChanged does not fire again after items have been added. In addition, the Loaded event doesnt seem to resolve this either. Are there any events that fire after the diagram has applied all data binding changes and the nodes have been rendered? Right now, it renders them all stacked on top of each other until I resize the window.
0
Miro Miroslavov
Telerik team
answered on 24 Feb 2012, 10:49 AM
Hi Anthony,

 Unfortunately there isn't such event for the moment. It's something we should solve for Q2, so I created new work item for it. Currently I think that maybe only LayoutUpdated event is suitable for your case. But you should be very careful with it and remove the handler after the initial layout.
We'll let you know if we find a better solution for this scenario.

All the best,
Miro Miroslavov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
kilhoffer
Top achievements
Rank 1
answered on 25 Feb 2012, 01:01 AM
LayoutUpdated doesnt help at all either. It fires immediately after SizeChanged, for obvious reasons. Both events occur before data is applied to the diagram. Is there any solution to this, or is the diagram not usable in situations where you programatically add nodes to it after it's been initially sized and laid out?
0
kilhoffer
Top achievements
Rank 1
answered on 26 Feb 2012, 09:36 PM
I've managed to overcome this issue. In my case, I had a ContentPresenter, into which I was placing a ViewModel instance with a DataTemplate containing the UserControl that hosted the Telerik Diagram. I changed this to instead manually create the UserControl and manually wire up the DataContext. Once I made that change, the diagram started behaving as expected. I'm still not sure why this is the case.
0
Petar Mladenov
Telerik team
answered on 29 Feb 2012, 03:48 PM
Hi Kilhoffer,

We created a feature request for an event that fires after all shapes are prepared and ready for layout. You can track its progress here.

Regards,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Kristoffer
Top achievements
Rank 1
answered on 31 Jan 2013, 12:58 PM
Can you please add such an event?

This functionality makes perfect sense. If I open a file containing the diagram and then want to autofit it, when should I do that?
It's been a year since the problem was originally reported :( 18 votes...
0
Petar Mladenov
Telerik team
answered on 04 Feb 2013, 07:16 AM
Hello Kristoffer,

We have updated the status of this Feature Request to "Resolved". In Q1 2013 you will be able to use the GraphSourceChanged event which fires when the Shapes are generated and measured. We have added a comment in the PITS item in the Description Section with more information.

Kind regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Kristoffer
Top achievements
Rank 1
answered on 13 Mar 2013, 12:57 PM
Just tried RadControls_for_WPF_2013_1_0311_DEV_hotfix. The GraphSourceChanged event is not fired when adding items to the GraphSource. Do I need to re-assign the entire GraphSource to get this event working?
0
Petar Mladenov
Telerik team
answered on 18 Mar 2013, 09:59 AM
Hello Kristoffer,

GraphSourceChanged is designed to fire when the GraphSource is assigned / re-set. It does not fire when adding removing links/nodes. For this purpose, you can use InternalItems.CollectionChanged or InternalLinks.CollectionChanged:

public class Graph : ObservableGraphSourceBase<Link, Node>
    {
        public Graph()
        {
            this.InternalItems.CollectionChanged += InternalItems_CollectionChanged;
            this.InternalLinks.CollectionChanged += InternalLinks_CollectionChanged;
        }
 
        void InternalLinks_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            throw new NotImplementedException();
        }
 
        void InternalItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            throw new NotImplementedException();
        }
    }

Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Diagram
Asked by
kilhoffer
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
kilhoffer
Top achievements
Rank 1
Petar Mladenov
Telerik team
Kristoffer
Top achievements
Rank 1
Share this question
or