ClipToBounds property
hasn??™t been set to True. The Viewbox isn??™t as tolerant of this error.)
Now consider what happens if you wrap the Canvas inside a proportionately sized Grid
cell and you don??™t specify the size of the Canvas. If you aren??™t using the Viewbox, this approach
works perfectly well??”the Canvas is stretched to fill the cell and the content inside is visible.
But if you place all this content in a Viewbox, this strategy fails. The Viewbox can??™t determine
the initial size, so it can??™t resize the Grid appropriately.
You can get around this problem by placing certain shapes (such as the Rectangle and
Ellipse) directly in an autosized container (such as the Grid). The Viewbox can then evaluate
the minimum size the Grid needs to fit its content and then scale it up to fit what??™s available.
However, the easiest way to get the size you really want in a Viewbox is to wrap your content in
an element that has a fixed size, whether it??™s a Canvas, a button, or something else. This fixed
size then becomes the initial size that the Viewbox uses for its calculations. Hard-coding a size
in this way won??™t limit the flexibility of your layout because the Viewbox is sized proportionately
based on the available space and its layout container.
nNote Regardless of whether you use the Viewbox, your graphic will be resized to compensate for different
system DPI settings (as described in Chapter 1).
Pages:
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673