我正在尝试创建一些圆形文本框,我在这个网站上找到了一些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>
答案 0 :(得分:1)
检查水平和垂直对齐属性,默认设置为拉伸
答案 1 :(得分:0)
尝试在TextBox上设置宽度。