Layout and AutoFit once diagram has loaded

11 posts, 0 answers
  1. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 21 Feb 2012 Link to this post

    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?
  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 21 Feb 2012 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 24 Feb 2012 Link to this post

    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.
  5. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 24 Feb 2012 Link to this post

    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 >>
  6. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 24 Feb 2012 Link to this post

    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?
  7. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 26 Feb 2012 Link to this post

    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.
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Feb 2012 Link to this post

    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 >>
  9. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 31 Jan 2013 Link to this post

    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...
  10. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 04 Feb 2013 Link to this post

    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.

  11. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2013 Link to this post

    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?
  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Mar 2013 Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready