none
Stackpanel element stretching

    Question

  • Hello,

    I have a stackpanel in which I want to have 3 elements.  It looks something like this:

    FileName (label)      ______textbox_______    Browse... (button

    So three elemets - a label, a textbox, and a browse button all lined up left to right.  My stackpanel has a horizontal orientation.  This typical "choose a file" layout is just a piece of a much larger screen with a grid, multiple checkboxes, etc. 

    My question is, is it possible to have the textbox (my middle element) "fill" all empty space in my stackpanel?  In other words, if the window is resized, can i make it so that my label is still docked to the left, my button is still to the right, and the middle textbox fills up the rest of the space.

    I sort of already got this working by using a dockpanel, but it seems like sort of a sloppy way of doing things.  I made my dockpanel just as tall as my textbox, and docked  the label to the left, textbox to the top, and button to the right.

    Is there a better way of doing this?  As I said, these three elements are just a piece of the entire screen, so adding in additional columns in a grid just for this seems wrong.  Should I be using a nested grid?  Is this good practice?

    Thanks for any suggestions you might have.

    shaun
    Thursday, September 04, 2008 10:22 PM

Answers

  • DockPanel or Grid should work fine.  DockPanel has a lighter layout algorithm, so unless you need to line up the elements in the row with elements in other rows, I'd say use it.  But honestly, I wouldn't sweat it either way.


    Dr. WPF - Online Office at http://drwpf.com/blog/
    • Proposed as answer by DutchMarcel Friday, September 05, 2008 8:21 AM
    • Marked as answer by Marco Zhou Thursday, September 11, 2008 10:09 AM
    Thursday, September 04, 2008 10:32 PM