AutoFit to fill whole space of the host window

7 posts, 1 answers
  1. Mikhail
    Mikhail avatar
    6 posts
    Member since:
    Oct 2012

    Posted 05 Nov 2012 Link to this post

    Hello,
    I have a diagram. When I call AutoFit() method it does not fill all the space available of the host window.I have to zoom in (manually) a bit to get a better fit. How do I achive AutoFit functionality that makes diagram as large as possible filling all visible space of the host window? Some function like ZoomToFit()?
    I attach two images of what I get by default and what I would like to get.
  2. Sarper
    Sarper avatar
    22 posts
    Member since:
    Aug 2012

    Posted 07 Nov 2012 Link to this post

    Hi Mikhail,
    You can achieve that issue by giving a little margin to AutoFit() method. It has two optional parameters;
    -Thickness margin => margin between diagram shapes and the host window
    -bool useAnimation =>  ( autofit animation )

    private void AutoFit_Click(object sender, RoutedEventArgs e)
    {
      this.diagram.AutoFit(new Thickness(5), true);
    }
    Here is the 5 value specifies a little margin. You can use that to fit your needs.
    Sincerely,
    Sarper
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mikhail
    Mikhail avatar
    6 posts
    Member since:
    Oct 2012

    Posted 07 Nov 2012 Link to this post

    Hi,
    Thanks for the answer.
    However, it does not work. I tried it.
    Margin works only if original diagram is bigger than view area.Then it zooms out enough to fit AND it sets proper Margins.
    But , if original diagram is smaller and fits already, but needs to be auto zoomed in(enlarged), AutoFit with margin does not work!
    It takes whole diagram and just puts it in center (like in my original bitmap i attached).
    I think , it is bug. It should automatically zoom in and respect margins provided.
    Let me know.
    Thanks!
  5. Sarper
    Sarper avatar
    22 posts
    Member since:
    Aug 2012

    Posted 07 Nov 2012 Link to this post

    Hi,
      I tried different scenarios but it worked fine for me. Can you give the code-snippet that you use? 

    Sincerely,
    Sarper
  6. Mikhail
    Mikhail avatar
    6 posts
    Member since:
    Oct 2012

    Posted 07 Nov 2012 Link to this post

    I am not allowed to attach zip files. It is a very simple case.
    Just try to Maximize your window and then call AutoFit with small margin. It will not work.
    It looks like it only works when window is resized a bit. But when window size is close to Maximized, it does not respect margins anymore.
  7. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 08 Nov 2012 Link to this post

    Hi Mikhail,

    The AutoFit method of the RadDiagram control simply centers and zooms out the diagram to display all items. This is why in case you have a large Diagram area with small diagram shapes, the AutoFit method will only center them.

    In order to stretch the shapes to fit to a certain area, you can use the FitTo() method - it takes a Rect object as an argument and fits the diagram to the specified rectangle. I attached a sample solution demonstrating this approach. Let me know if it helps.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Mikhail
    Mikhail avatar
    6 posts
    Member since:
    Oct 2012

    Posted 08 Nov 2012 Link to this post

    Thank you for the fast answer!
    Then if AutoFit only centers it (eventhough I provided margins), then it does not consider provided margins! Which I think is wrong and confusing. There should be another function related to Zoom. It should be called ZoomToFit()!
    Anyway, I understood your point about using FitTo(). That's what I will do.
    Thanks anyway.
    Mikhail.
Back to Top
UI for WPF is Visual Studio 2017 Ready