UserControl 中的圆角未显示
Rounded Corners in UserControl not showing
我正在尝试让我的 UserControl 显示圆角。
这是我的标记:
<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="220" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
<Grid.Background>
<ImageBrush ImageSource="{StaticResource NavyBlueGround}" />
</Grid.Background>
<Label Grid.Column="1" Grid.Row="0" Style="{StaticResource GelTitle}" Content="Customer Search" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
<Label Grid.Row="1" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer First Name" VerticalAlignment="Bottom" />
<TextBox Grid.Row="2" Grid.Column="1" Name="txtForeName" Background="White" VerticalContentAlignment="Center"/>
<Label Grid.Row="3" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer Last Name" VerticalAlignment="Bottom" />
<TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" FontSize="14" Text="hello" VerticalContentAlignment="Center" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" />
<Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" Style="{StaticResource GelButton}" Content="Search" Click="btnCustomerSearch_Click" VerticalAlignment="Center" />
</Grid>
</Border>
这是它的样子:
与其将背景用于网格,不如将其用于边框。
<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Border.Background>
<ImageBrush ImageSource="{StaticResource NavyBlueGround}" />
</Border.Background>
编辑:这个问题的原因是边框(当 padding=5 时)将其子元素的边距设置为 5 个像素。同时定义 CornerRadius 设置网格的边距更进一步。
因此 Grid(及其背景)的边界不是出现圆角的地方。
你肯定有别的事情要发生。我使用 UserControl 将您的代码粘贴到一个新项目中,它呈现得很好。
如果新项目不适合您,您能否提供更多详细信息,并比较差异以帮助解决问题?
我正在尝试让我的 UserControl 显示圆角。
这是我的标记:
<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="220" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
<Grid.Background>
<ImageBrush ImageSource="{StaticResource NavyBlueGround}" />
</Grid.Background>
<Label Grid.Column="1" Grid.Row="0" Style="{StaticResource GelTitle}" Content="Customer Search" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
<Label Grid.Row="1" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer First Name" VerticalAlignment="Bottom" />
<TextBox Grid.Row="2" Grid.Column="1" Name="txtForeName" Background="White" VerticalContentAlignment="Center"/>
<Label Grid.Row="3" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer Last Name" VerticalAlignment="Bottom" />
<TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" FontSize="14" Text="hello" VerticalContentAlignment="Center" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" />
<Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" Style="{StaticResource GelButton}" Content="Search" Click="btnCustomerSearch_Click" VerticalAlignment="Center" />
</Grid>
</Border>
这是它的样子:
与其将背景用于网格,不如将其用于边框。
<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Border.Background>
<ImageBrush ImageSource="{StaticResource NavyBlueGround}" />
</Border.Background>
编辑:这个问题的原因是边框(当 padding=5 时)将其子元素的边距设置为 5 个像素。同时定义 CornerRadius 设置网格的边距更进一步。
因此 Grid(及其背景)的边界不是出现圆角的地方。
你肯定有别的事情要发生。我使用 UserControl 将您的代码粘贴到一个新项目中,它呈现得很好。
如果新项目不适合您,您能否提供更多详细信息,并比较差异以帮助解决问题?