2012-11-01 53 views
0

我想創建一些圓角的文本框,並且我在這個網站上發現了一些XAML,並且它在創建我想要的文本框時效果很好。但是,如果我調整窗口大小,無論是在設計器還是運行時,文本框的高度和寬度都會隨之改變,並且會變形並無用。這個XAML爲什麼會產生用窗口調整大小的文本框?

我還在學習WPF,所以我確信我缺少一些簡單的東西。謝謝你的幫助。

<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> 

回答

1

檢查它們默認設置爲伸展的水平和垂直對齊屬性

+0

就是這樣!謝謝,我知道這會很簡單。 – Dbloom

0

嘗試設置在文本框的寬度。