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

AutoFit from NavigationPanel

3 Answers 58 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Davide
Top achievements
Rank 1
Davide asked on 21 Nov 2013, 10:53 AM
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

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 26 Nov 2013, 11:24 AM
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 >>
0
Barış
Top achievements
Rank 1
answered on 16 Oct 2015, 12:14 PM

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

0
Martin Ivanov
Telerik team
answered on 21 Oct 2015, 10:48 AM
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
Tags
Diagram
Asked by
Davide
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Barış
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or