locked
How to make stackpanel width fit the children's combined width?

    Question

  • How do I make a stackpanel's width the same as the children's combined widths?
    Tuesday, October 14, 2014 10:14 PM

Answers

  • Figured it out.

    Just make horizontalallignment and verticalallignment of every parent and grandparent of the textbox "center".

    • Marked as answer by RandyPete Wednesday, October 15, 2014 2:58 AM
    Wednesday, October 15, 2014 2:58 AM

All replies

  • You can give your stack panel a name like x:Name="myStack".  Then in code behind do myStack.Width = control1.Width + control2.Width.

    Bret Bentzinger (MSFT) @awehellyeah

    Tuesday, October 14, 2014 11:15 PM
    Moderator
  • You can give your stack panel a name like x:Name="myStack".  Then in code behind do myStack.Width = control1.Width + control2.Width.

    Bret Bentzinger (MSFT) @awehellyeah

    Well, gee, thanks.  Unfortunately, I'm looking to do something a lot more complicated than having a couple of controls in a stackpanel.

    Is there no way to do this with just xaml?

    Added by edit.

    Actually, is there a way to bind the width of an object to an object inside a usercontrol on that page?

    • Edited by RandyPete Wednesday, October 15, 2014 12:36 AM
    Wednesday, October 15, 2014 12:18 AM
  • Figured it out.

    Just make horizontalallignment and verticalallignment of every parent and grandparent of the textbox "center".

    • Marked as answer by RandyPete Wednesday, October 15, 2014 2:58 AM
    Wednesday, October 15, 2014 2:58 AM