我不知道如何“填充”剪辑,所以我用代码制作了剪辑。如果您需要更多帮助添加更多属性来控制颜色等,请告诉我。
开始:
Code:
public class Tabby : HeaderedContentControl
{
static Tabby()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Tabby), new FrameworkPropertyMetadata(typeof(Tabby)));
}
public double DogEar
{
get { return (double)GetValue(DogEarProperty); }
set { SetValue(DogEarProperty, value); }
}
public static readonly DependencyProperty DogEarProperty =
DependencyProperty.Register("DogEar",
typeof(double),
typeof(Tabby),
new UIPropertyMetadata(8.0, DogEarPropertyChanged));
private static void DogEarPropertyChanged(
DependencyObject obj,
DependencyPropertyChangedEventArgs e)
{
((Tabby)obj).InvalidateVisual();
}
public Tabby()
{
this.SizeChanged += new SizeChangedEventHandler(Tabby_SizeChanged);
}
void Tabby_SizeChanged(object sender, SizeChangedEventArgs e)
{
var clip = new PathGeometry();
clip.Figures = new PathFigureCollection();
clip.Figures.Add(
new PathFigure(
new Point(0, 0),
new[] {
new LineSegment(new Point(this.ActualWidth - DogEar, 0), true),
new LineSegment(new Point(this.ActualWidth, DogEar), true),
new LineSegment(new Point(this.ActualWidth, this.ActualHeight), true),
new LineSegment(new Point(0, this.ActualHeight), true) },
true)
);
this.Clip = clip;
}
}
通用.xaml
<Style TargetType="{x:Type local:Tabby}">
<Setter Property="Padding"
Value="5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Tabby}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Border CornerRadius="3,0,0,0"
BorderBrush="Black"
BorderThickness="1"
Background="Black">
<ContentPresenter Content="{TemplateBinding Header}"
Margin="{TemplateBinding Padding}" />
</Border>
<Border CornerRadius="0,0,3,3"
BorderBrush="Black"
BorderThickness="1"
Background="White"
Grid.Row="1">
<ContentPresenter Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
使用它:
<my:Tabby DogEar="12"
x:Name="tabby1">
<my:Tabby.Header>
<TextBlock Foreground="White">Header</TextBlock>
</my:Tabby.Header>
<my:Tabby.Content>
<TextBlock Text="Content can be anything" />
</my:Tabby.Content>
</my:Tabby>