开发者

How to get WPF controls to size correctly?

I'm just starting out with WPF and I'm trying to layout a UI.

I have a StackPanel and within it's bounds I want two listboxes stacked vertically, each covering half of the container panel - regardless of what contents are in them.开发者_运维百科 So far, the listboxes are resizing depending in the items in them, so when they are empty, they don't cover any of the container panel, and as items are added they resize and look pretty ugly.

In the old Winforms days I'd trap a resize event and set the height manually. I know that's not the "right" way anymore, but I'm not sure what the right way is!

So, any suggestions?


Use a grid with one column and two rows, instead of the stack panel.
Don't set the row height to anything, by default it it will share the height equally between any rows.

Each row will occupy 50% of the grid height. Add the list boxes to col=0, row=0 & col=0, row=1 on the grid.

If you want to change the porportion, say 1/3 & 2/3 Set one row height to "2*" and the other to "1*"

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜