C# 在WPF控件中填充标头有什么技巧吗?

C# 在WPF控件中填充标头有什么技巧吗?,c#,wpf,C#,Wpf,我有这个控制: <UserControl x:Class="com.Controls.AcceptedTransformation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xm

我有这个控制:

<UserControl x:Class="com.Controls.AcceptedTransformation"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:com.Controls"
         mc:Ignorable="d" 
         >
<Grid>
    <Border CornerRadius="6" BorderBrush="Gray" Background="Transparent" BorderThickness="2">
        <StackPanel Orientation="Vertical" Background="Transparent" Margin="3,3,3,3" Width="170">
            <StackPanel Orientation="Horizontal" Background="DarkOliveGreen" >
                <TextBlock Foreground="AntiqueWhite" VerticalAlignment="Center" FontWeight="ExtraBold">Column:</TextBlock>
                <TextBlock x:Name="tbkColumnName" Foreground="AntiqueWhite" Margin="3,0,0,0" VerticalAlignment="Center" FontWeight="ExtraBold">Var1</TextBlock>
            </StackPanel>
            <TextBlock x:Name="tbkTransformationList" Foreground="AntiqueWhite" Margin="0,3,0,0">Var2</TextBlock>
            <StackPanel Orientation="Horizontal">
                <TextBlock Foreground="AntiqueWhite" Margin="0,0,5,0">Sample:</TextBlock>
                <TextBlock x:Name="tbkSample" Foreground="AntiqueWhite"></TextBlock>
            </StackPanel>
        </StackPanel>
    </Border>
</Grid>

专栏:
Var1
Var2
样本:
看起来是这样的:


有没有什么简单的方法可以让绿色框填充顶部、圆角和所有内容?

一旦删除边距,您将遇到的问题是内容仍然有方形的角,而边框没有

你可以剪辑内容,但是构建一个几何体来剪辑内容是很复杂的事情。作为一个基本的(软件)工程原理,我们应该使用最简单的东西来完成这项工作

作为一个以问题为导向的加号,这种方法也是一种横向思维技巧或“欺骗”

要做到这一点,我们可以设置已剪裁的边界背景。 把上面的东西弄透明。 我们可以使用在同一位置有两个挡块的lineargradientbrush实现硬边过渡

像这样:

    <Border CornerRadius="6" BorderBrush="Gray" BorderThickness="2">
        <Border.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <GradientStop Color="DarkOliveGreen" Offset="0" />
                <GradientStop Color="DarkOliveGreen" Offset=".33" />
                <GradientStop Color="Black" Offset=".33" />
                <GradientStop Color="Black" Offset="1" />
            </LinearGradientBrush>
        </Border.Background>
        <StackPanel Orientation="Vertical" Background="Transparent" Width="170">
            <StackPanel Orientation="Horizontal" >
                <TextBlock Foreground="AntiqueWhite" VerticalAlignment="Center" FontWeight="ExtraBold">Column:</TextBlock>
                <TextBlock x:Name="tbkColumnName" Foreground="AntiqueWhite" Margin="3,0,0,0" VerticalAlignment="Center" FontWeight="ExtraBold">Var1</TextBlock>
            </StackPanel>
            <TextBlock x:Name="tbkTransformationList" Foreground="AntiqueWhite" Margin="0,3,0,0">Var2</TextBlock>
            <StackPanel Orientation="Horizontal">
                <TextBlock Foreground="AntiqueWhite" Margin="0,0,5,0">Sample:</TextBlock>
                <TextBlock x:Name="tbkSample" Foreground="AntiqueWhite"></TextBlock>
            </StackPanel>
        </StackPanel>
    </Border>

专栏:
Var1
Var2
样本:
将其粘贴在窗口的网格内,并将大小设置为内容。。。我得到:


Id首先删除此
Margin=“3,3,3,3”
OMG。我想我需要小睡一会儿。谢谢。虽然这还不能完全解决问题。不,你说得对,正方形向上延伸到半径内。但这比以前好多了……你可以试着在内部堆叠面板上放置一个厚度为0的边框和一个带半径的背景色,但它怀疑它是否完美。你也可以在所有的东西上加上外部的边界(因为它很厚),这样可能会产生最好的效果!谢谢我知道这一定是个“把戏”,非常优雅,看起来很棒。非常感谢。