4

Does anyone know how to set the TextBox.Width property to fill up the remainder of the parent container in code? In Xaml, I would simply set the Width property to *, but I can't figure out how to do this in code.

Thanks, Roy

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
LPCRoy
  • 935
  • 2
  • 12
  • 19

2 Answers2

8

Are you looking for

HorizontalAlignment="Stretch"

Related answers:

WPF - setting HorizontalAlignment= Stretch to Textbox in StackPanel

HorizontalAlignment=Stretch, MaxWidth, and Left aligned at the same time?

Community
  • 1
  • 1
John T
  • 23,735
  • 11
  • 56
  • 82
3

Try the following

textBox.Width = Double.NaN;

Double.NaN (not a number) is the equivalent of any size.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454