From the course: Windows Presentation Foundation: 2 Layout

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Adjust content alignment

Adjust content alignment

From the course: Windows Presentation Foundation: 2 Layout

Start my 1-month free trial

Adjust content alignment

- [Instructor] In this video, I'll look at how the HorizontalAlignment and VerticalAlignment properties affect the size of a child element. Here's the example I'll start with. It's on MainWindow.xaml and I have a StackPanel and I have a LetterBox where I've hardcoded the width to 120 pixels. When the width is hardcoded, that's considered the desired width and in this case, I'm in a StackPanel, and the StackPanel honors my desired width. Now when you set the Width to Auto, than the element falls back to its internal rules, and in my case, for my LetterBox, the internal rules are, if you don't specify a height and width, default back to 80 pixels in height and 80 pixels in width. Now if you look at LetterBox B over here, you can see it's 80 pixels high but it's more than 80 pixels in width, so what's going on there? Well here's what's going on. When you specify HorizontalAlignment = Stretch, or VerticalAlignment = Stretch, you're granting permission to the panel to change the final…

Contents