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

Not working AutoFit()

3 Answers 149 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Svyatoslav
Top achievements
Rank 1
Svyatoslav asked on 20 Mar 2017, 07:16 AM

Good afternoon. Not working AutoFit(). After loading the diagram, should be AutoFit, but the screen always goes in the center of the diagram. I have tried the following combinations:

1)    like in this post  http://www.telerik.com/forums/autofit-to-fill-whole-space-of-the-host-window

this.diagram.AutoFit(new Thickness(5), true); 

it didn't help and I tried:

2)      Rect allShapesBounds = this.diagram.Shapes.GetEnclosingBounds();
            Rect inflatedRect = allShapesBounds.InflateRect(10, 10, 10, 10);
            this.diagram.FitTo(inflatedRect);

and it did not help too and I tried so:

3)         Rect allShapesBounds = this.diagram.Shapes.GetEnclosingBounds();
            Rect inflatedRect = allShapesBounds.InflateRect(10, 10, 10, 10);                                                                                                                                    this.diagram.BringIntoView(inflatedRect);

 

3 Answers, 1 is accepted

Sort by
0
Svyatoslav
Top achievements
Rank 1
answered on 20 Mar 2017, 07:25 AM

Now my code looks like this:

 

    <telerik:RadDiagram x:Name="diagram"  
                         Grid.Row="1"  IsEditable="True" Grid.Column="1" MinWidth="500" BorderThickness="1" telerik:StyleManager.Theme="Windows8"   telerik:DiagramAnimations.IsPanAnimationEnabled="True"
                         SelectionMode="Extended" RouteConnections="True" 
                         ConnectionBridge="Bow" 
                         telerik:PersistenceManager.StorageId="diagram"  
                         primitives:BackgroundGrid.IsDynamic="True"
                         AllowDrop="True"  IsSnapToItemsEnabled="True"  
                         IsRotationEnabled="False"     
telerik:DiagramExtensionProperties.ShouldDetachConnections="True"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                        Zoom="{Binding ZoomLevel}"
Background="{Binding SelectedColor, ElementName=BackgroundColorEditor, Converter={StaticResource customColorToBrushConverter}}"
primitives:BackgroundGrid.IsGridVisible="{Binding ElementName=ShowGridCheckBox, Path=IsChecked}"
primitives:BackgroundGrid.LineStroke="{Binding SelectedColor, ElementName=GridColorEditor, Converter={StaticResource customColorToBrushConverter}}"
primitives:BackgroundGrid.CellSize="{Binding CellSize}"
IsSnapToGridEnabled="{Binding IsSnapEnabled}" SnapX="{Binding SnapValue}"
SnapY="{Binding SnapValue}"
primitives:BackgroundPageGrid.IsGridVisible="{Binding ElementName=ShowPagesCheckBox, Path=IsChecked}"
primitives:BackgroundPageGrid.LineStroke="{Binding SelectedColor, ElementName=PagesColorEditor, Converter={StaticResource customColorToBrushConverter}}">     
                    </telerik:RadDiagram> 

 

 

  public FunctionDiagram()
        {
           
            InitializeComponent();
            Loaded += Function_Loaded;
            Unloaded += FunctionDiagram_Unloaded;
           
            this.diagram.AutoFit();
            DiagramConstants.MinimumZoom = 0.25;
            DiagramConstants.MaximumZoom = 10;
            this.zoomLevel = 1d;
            this.items = new HierarchicalGalleryItemsCollection();
            Brush DiagramColor = new SolidColorBrush(BackgroundColorEditor.SelectedColor);
            diagram.Background = DiagramColor;
        }

0
Petar Mladenov
Telerik team
answered on 22 Mar 2017, 09:35 AM
Hi Svyatoslav,

I guess you are calling AutoFit function too early. Have you tried calling it in Loaded event handler ?
Also, you can try AutoFitAsync() which should generally do its job on the next framework's layout update.

Regards,
Petar Mladenov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Svyatoslav
Top achievements
Rank 1
answered on 22 Mar 2017, 09:47 AM
AutoFitAsync() solved the problem. thank you Petar. Sorry for the stupid question
Tags
Diagram
Asked by
Svyatoslav
Top achievements
Rank 1
Answers by
Svyatoslav
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or