(If you set an explicit height and width, your
shape is sized within those bounds. For example, if you set a Width of 10 and a
Height of 100 for a rectangle, you??™ll get a 100 ?— 100 rectangle that??™s clipped to fit
an invisible 10 ?— 100 box.)
Figure 13-4 shows the difference between Fill, Uniform, and UniformToFill.
CHAPTER 13 n SHAPES, TRANSFORMS, AND BRUSHES 376
Figure 13-4. Filling three cells in a Grid
Usually, a Stretch value of Fill is the same as setting both HorizontalAlignment and
VerticalAlignment to Stretch. The difference occurs if you choose to set a fixed Width or Height
on your shape. In this case, the HorizontalAlignment and VerticalAlignment values are simply
ignored. However, the Stretch setting still has an effect??”it determines how your shape content
is sized within the bounds you??™ve given it.
nTip In most cases, you??™ll size a shape explicitly or allow it to stretch to fit. You won??™t combine both
approaches.
So far, you??™ve seen how to size a Rectangle and an Ellipse, but what about placing them
exactly where you want them? WPF shapes use the same layout system as any other element.
However, some layout containers aren??™t as appropriate. For example, the StackPanel, Dock-
Panel, and WrapPanel often aren??™t what you want because they??™re designed to separate
elements.
Pages:
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668