Search code examples
xamltextboxwinui-3winui

Change the Height of a TextBox input area in WinUI 3 XAML


I've noticed when I change the height of a TextBox control in WinUI 3 XAML, the overall control height changes (not just the input area) and it will cut off bottom of the input area if I make the height less than around 56 if there is a header. For example:

        <TextBox
            x:Name="MyTextBox"
            Height="45"
            Width="Stretch"
            Header="A Text Box" />

Any way around this? It's easy to make the text box taller, but I want the input area shorter than the default.


Solution

  • In the DefaultTextBoxStyle,

    • MinHeight is set to TextControlThemeMinHeight (default: 32)
    • Padding is set to TextControlThemePadding (default: 10,5,6,6)

    Try setting both MinHeight and Padding to 0:

    <TextBox
        x:Name="MyTextBox"
        Height="45"
        MinHeight="0"
        Padding="0"
        Header="A Text Box"
        Text="ABCDE" />
    

    enter image description here

    If you are not familiar with DefaultTextBoxStyle, check the generic.xaml file.