locked
Zoom grid to fit?

    Question

  • Suppose I have a grid inside a scrollviewer. Is there a way to make the grid zoom to fit the height of the scrollviewer? If a scrollviewer shouldn't be used, what should I use to make this happen?

    What I'm trying to accomplish is have a grid or stack or usercontrol inside a container.  Then I can programmatically change the size of the container and I want the child inside to zoom to fit the height of the container.

    Tuesday, April 7, 2015 11:34 PM

Answers

  • I'm not sure I quite get what you're trying to do, but it sounds like a ViewBox or a ScaleTransform may be more appropriate than using a ScrollViewer to Zoom to a constant value.

    If you want the users to be able to control the Zoom but to default to a full screen then you will probably need to do the math to find the appropriate scale factor and then set that on the ScrollViewer (or ScaleTransform).

    Wednesday, April 8, 2015 3:00 AM
    Owner
  • Please check out the ViewBox documentation.

    Again, if you need more help with this please explain what you are trying to do more clearly.

    Thursday, April 9, 2015 1:20 AM
    Owner

All replies

  • Can you explain your scenario in more detail?

    By default the Grid will size to fit its container, so if you put a Grid in a ScrollViewer it will fit the Height and Width of the ScrollViewer. This probably isn't what you want, since the ScrollViewer only scrolls if the contents are larger.

    To do something more useful you can put a horizontal StackPanel inside your ScrollViewer. This will still fit to the height of the ScrollViewer and to the width of its contents. With enough contents to overflow the ScrollViewer it will scroll.

    If you don't want to use a control which will auto-fit to the ScrollViewer then you can get the ActualHeight of the ScrollViewer and set your content control's height to match. The ActualHeight is not readily bindable, so you'll need to listen to the ScrollViewer's SizeChanged event instead (see the Remarks in the ActualHeight docs).

    Wednesday, April 8, 2015 1:13 AM
    Owner
  • I'm talking about the zoom property of the scrollviewer.

    I've already built these usercontrols very precisely size-wise.  This is for an LOB.  I don't want to go back and change the sizes of the textboxes and other things in the dozens of usercontrols.

    Before, I fitted 2 of these in a single printout page.  Now, I want to fit 6.  And since I don't want to go through and change the fontsizes and all the other properties, putting them in scrollviewers and use the zoom property seems the logical choice.

    I've managed to scale the zoom perfectly to fit 6 usercontrols in a single page and still have very neatly printed out pages.  The guys in the office will like this when I send out the upgrade. 

    My next logical step is I want to give the user the ability to control the sizes of the usercontrols.  This is where my question comes in.  Is there a way to make the zoom auto-fit? 


    The point is not to have any scrolling going on for each usercontrol.  The entire page is scrollable, but my colleagues want to see what will print when they work with my app.  This is why each page is scrollable, but the usercontrols have to be zoomed to the sizes they want to give to the scrollviewers.  Make sense?
    • Edited by RandyPete Wednesday, April 8, 2015 2:35 AM
    Wednesday, April 8, 2015 2:31 AM
  • I'm not sure I quite get what you're trying to do, but it sounds like a ViewBox or a ScaleTransform may be more appropriate than using a ScrollViewer to Zoom to a constant value.

    If you want the users to be able to control the Zoom but to default to a full screen then you will probably need to do the math to find the appropriate scale factor and then set that on the ScrollViewer (or ScaleTransform).

    Wednesday, April 8, 2015 3:00 AM
    Owner
  • Never use a viewbox before. What properties to zoom with it?
    Wednesday, April 8, 2015 1:18 PM
  • Please check out the ViewBox documentation.

    Again, if you need more help with this please explain what you are trying to do more clearly.

    Thursday, April 9, 2015 1:20 AM
    Owner