Sunday, May 03, 2009

WPF: StackPanel vs DockPanel and ScrollViewer

Mucking around with WPF (Microsoft's latest and nicest way of putting GUIs together), I spent an hour googling to find the following gem.

A StackPanel allows its children to occupy whatever space they need. Therefore, you will never see a scroll bar you have attached (via a ScrollViewer) to a child of a StackPanel unless you have explicitly set the ScrollViewer Height property. You won't see the scroll bar because the child will be under the impression it has all the room it needs.

A DockPanel, on the other hand, requests that its children limit themselves to the area in the window occupied by the DockPanel.

On the left you can see an application where a ScrollViewer is attached to a StackPanel in a child of a DockPanel. The scroll bar is visible because the StackPanel cannot be fully displayed in the area made available by the DockPanel. The document structure looks something like this:

DockPanel
...
TabControl DockPanel.Dock=Top
TabItem
ScrollViewer
StackPanel



On the right you can see the same application where the ScrollViewer's parent is a child of a StackPanel. The scroll bar is not shown because the child StackPanel thinks it has all the display area it needs. This document structure looks something like this:

StackPanel
...
TabControl DockPanel.Dock=Top
TabItem
ScrollViewer
StackPanel


5 comments:

Unknown said...

Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
Selenium training in Chennai

Selenium training in Bangalore

Deepali M said...
This comment has been removed by the author.
Sai Institutions said...

Very happy to say your post is very interesting to read.
cruise ship training and placement in chennai
best visual communication insitute in chennai
Carving classes in Chennai
hotel management institute in chennai
hotel management course in chennai
hotel management College in chennai
Fashion Design Course in Chennai

Selena said...

You have made your points in a smart way. I am impressed with how interesting you have been able to present this content. Thanks for sharing a nice information. Do support us
BSC Interior Design Colleges in Bangalore
Fashion Designing Courses In Bangalore
Interior Design Courses In Chennai
Fashion Technology Courses In Chennai
BSC Interior Design Colleges in Chennai

deiva said...

After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
oracle training in chennai

oracle training in omr

oracle dba training in chennai

oracle dba training in omr

ccna training in chennai

ccna training in omr

seo training in chennai

seo training in omr