0

我正在尝试创建一些圆形文本框,并且我在此站点上找到了一些 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>

4

2 回答 2

1

检查水平和垂直对齐属性,它们默认设置为拉伸

于 2012-11-01T21:45:44.637 回答
0

尝试在 TextBoxes 上设置宽度。

于 2012-11-01T21:35:01.333 回答