Dbloom
Dbloom

Reputation: 1412

Why does this XAML produce textboxes that resize with the window?

I am trying to create some rounded textboxes, and I have found some XAML here on this site, and it works well at creating the textboxes I want. However, if I resize my window, either in the designer or at run time, the height and width of the textboxes change with it, and they get distorted and useless.

I'm still learning WPF, so I'm sure I am missing something simple. Thanks for any help.

<Window x:Name="mainWindow" x:Class="CMDB_Express.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CMDB Express" Height="289" Width="600" SizeToContent="Height" MinHeight="289">
<Window.Resources>
    <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
        <Border Background="{TemplateBinding Background}"
                x:Name="Bd" BorderBrush="Black"
                BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10">
        </Border>
    </ControlTemplate>
</Window.Resources>
<Grid>
    <TextBox Name="txtDOE" KeyboardNavigation.TabIndex="0" Template="{StaticResource TextBoxBaseControlTemplate}" Margin="139,59,339,159" FontFamily="Segoe UI" FontSize="18" VerticalContentAlignment="Center" MaxLength="7" />
    <Label x:Name="lblDOE" Content="DOE Number: " HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" FontFamily="Segoe UI" Height="33" FontSize="18"/>
    <TextBox Name="txtCustodian" KeyboardNavigation.TabIndex="1" Template="{StaticResource TextBoxBaseControlTemplate}" Margin="139,121,339,97" FontFamily="Segoe UI" FontSize="16" VerticalContentAlignment="Center" />
    <Label x:Name="lblCustodian" Content="Custodian: " HorizontalAlignment="Left" Margin="35,134,0,0" VerticalAlignment="Top" FontFamily="Segoe UI" Height="33" FontSize="18"/>
    <TextBox Name="txtBuilding" KeyboardNavigation.TabIndex="2" Template="{StaticResource TextBoxBaseControlTemplate}" Margin="396,59,75,159" FontFamily="Segoe UI" FontSize="16" VerticalContentAlignment="Center" />
    <Label x:Name="lblBuilding" Content="Building: " HorizontalAlignment="Left" Margin="307,72,0,0" VerticalAlignment="Top" FontFamily="Segoe UI" Height="33" FontSize="18"/>
    <TextBox Name="txtRoom" KeyboardNavigation.TabIndex="3" Template="{StaticResource TextBoxBaseControlTemplate}" Margin="396,121,75,97" FontFamily="Segoe UI" FontSize="16" VerticalContentAlignment="Center" />
    <Label x:Name="lblRoom" Content="Room: " HorizontalAlignment="Left" Margin="325,134,0,0" VerticalAlignment="Top" FontFamily="Segoe UI" Height="33" FontSize="18"/>
    <TextBox x:Name="txtDnsName" KeyboardNavigation.TabIndex="1" Template="{StaticResource TextBoxBaseControlTemplate}" Margin="139,183,339,35" FontFamily="Segoe UI" FontSize="16" VerticalContentAlignment="Center" />
    <Label x:Name="lblDnsName" Content="DNS Name: " HorizontalAlignment="Left" Margin="35,196,0,0" VerticalAlignment="Top" FontFamily="Segoe UI" Height="33" FontSize="18"/>
    <Expander x:Name="expAdvanced" Header="Advanced..." HorizontalAlignment="Left" Margin="262,234,0,0" VerticalAlignment="Top">
        <Grid Background="#FFE5E5E5">
            <Label x:Name="lblExpanded" Content="EXPANDED!"/>
        </Grid>
    </Expander>
</Grid>

Upvotes: 0

Views: 740

Answers (2)

Simon Wood
Simon Wood

Reputation: 634

Check horizontal and vertical alignment properties they are set to stretch by default

Upvotes: 1

Aris
Aris

Reputation: 191

Try setting the width on the TextBoxes.

Upvotes: 0

Related Questions