![Tabby](https://i.stack.imgur.com/Em8bk.png)
我不知道如何「填充」剪輯,因此我使用代碼製作剪輯。讓我知道如果你需要更多的幫助,增加更多的屬性來控制顏色等 這裏所說:
代碼:
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;
}
}
Generic.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>
完美!這已經死了 - 我所需要的。現在我總是從WPF中重新看到一個問題......您是如何在世界上學會如何提出您所做的事情的?真正以有用的方式學習WPF的資源似乎非常稀缺。 – RubyHaus
五年前,我做了你現在所處的困難部分。我閱讀這些書籍,編寫了多個項目,犯了錯誤,並問了其他人(當時並沒有那麼多人,但我有幸能夠接觸到一些WPF工作的人)。即使現在我仍然在學習。請進,你會到達那裏。 –