AutoFit from NavigationPanel

4 posts, 0 answers
  1. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 21 Nov 2013 Link to this post

    Hi,
    I've noticed that when the AutoFit button is pressed in the RadDiagramNavigationPane the AutoFit() function is called. My intent is to call the AutoFit(Thickenss margin, bool useAnimation) setting the margin to 0. I tried to override the AutoFit() method but this is not possible. Is there another way to do this? When i call AutoFit() I see that a margin is present while when I call the AutoFit(new Thickness(0)) this margin is absent. Is this thickness a propert of the diagram that can be set?

    Thx

    Davide
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 Nov 2013 Link to this post

    Hi Davide,

    In order to change such core functionality of the DiagramNavigationPane control, you need to create a custom control deriving from ours. I can see that the Command property of that button is bound to the AutoFit command of that RadDiagram. After you derive our control, you will be able to override the OnApplyTemplate() method. In that method you can gain access to that button.

    Once you do so, you will be able to set the command to null and subscribe to its Click event. by doing so you will be able to implement your custom fitting logic that will be triggered when that button is pressed. You can use the following snippet:

    public class MyNavigationPane : RadDiagramNavigationPane
    {
        RadButton autofitButton;
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            autofitButton = this.FindChildByType<RadButton>();
            autofitButton.Command = null;
            autofitButton.Click += autofitButton_Click;
        }
     
        void autofitButton_Click(object sender, RoutedEventArgs e)
        {
            //Custom fitting logic
        }
    }
    Please give this approach a try and let us know if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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. DevCraft banner
  4. Barış
    Barış avatar
    19 posts
    Member since:
    Jul 2015

    Posted 16 Oct 2015 in reply to Pavel R. Pavlov Link to this post

    Hello, 

    Is there a way to merge undo/redo  function with autofit. What I exactly need is, undo and redo autofit and zoom level change when user scrolled.

    The users complained about layout function does not revert zoom level. 

     Thank you in advance

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 21 Oct 2015 Link to this post

    Hi Barış,

    You can achieve the desired functionality you can use UndoableDelegateCommand and the diagram's UndoRedoService to execute it. The command allows you to execute an action and its undo logic. You can execute the command when you call the AutoFit() method and in the PreviewZoom event handler. Here is an example for this approach:
    void diagram_PreviewZoom(object sender, DiagramZoomEventArgs e)
    {
        var service = this.diagram.UndoRedoService;
        var zoom = this.diagram.Zoom;
     
        var command = new UndoableDelegateCommand("Zoom",
            (o) => { },
            (o) =>
            {
                this.diagram.Zoom = zoom;
            });
        service.ExecuteCommand(command);
    }
     
    void MainWindow_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        var service = this.diagram.UndoRedoService;
        var viewPortRect = new Rect(this.diagram.Viewport.TopLeft, this.diagram.Viewport.BottomRight);
     
        var command = new UndoableDelegateCommand("AutoFit",
            (o) =>
            {
                this.diagram.AutoFit();
            },
            (o) =>
            {
                this.diagram.BringIntoView(viewPortRect);
            });           
        service.ExecuteCommand(command);
    }
    I hope this works for you.

    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