私はクリップを '塗りつぶす'方法を知らないので、クリップでコードを作りました。
コード:
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からいつも浮かび上がっているような1つの質問...あなたがしたことを思い付くことを世界でどうやって学んだのですか?このような便利なファッションでWPFを実際に学習するためのリソースは、信じられないほど不足しているようです。 – RubyHaus
5年前、私はあなたが今いる厳しい部分をしました。私はその本を読んで、複数のプロジェクトをコーディングし、間違いを犯したり、他の人に尋ねました(その周りにはそれほど多くはありませんでしたが、私はWPFで働く人々の一部にアクセスできるほど幸運でした)。そして今でも私はまだ学んでいます。ハングアップすると、あなたはそこに着くでしょう。 –