如何在wpf中创建切角
我有一些代码
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="8" Margin="0,0,5,0">
<!--Background="#FDFFC1"-->
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#FFFFFFFD" />
<GradientStop Color="#FEFD9A" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="10,10,0,0" Height="22" VerticalAlignment="Top">
<Label Foreground="Black" FontSize="10" Margin="5,0,0,0" HorizontalAlignment="Left"
VerticalAlignment="Center" Content="Text" />
</Border>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Margin="5,2,0,2">
<Image x:Name="tooltipImage" Width="18" Height="18"
Source=""
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="1" Margin="5,5,5,5">
<TextBlock
Foreground="Black"
Text="Test" FontSize="10"
VerticalAlignment="Center" xml:space="preserve"
HorizontalAlignment="Center"
TextAlignment="Justify" MaxWidth="200"
TextWrapping="Wrap"/>
</Border>
对于这个边框,我希望它的右下角就像是用剪刀剪下来的或像一张被剪下来的纸。我想我需要使用路径或一些几何图形,但我不知道具体如何使用。
提前致谢 !
I have some code
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="8" Margin="0,0,5,0">
<!--Background="#FDFFC1"-->
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#FFFFFFFD" />
<GradientStop Color="#FEFD9A" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="10,10,0,0" Height="22" VerticalAlignment="Top">
<Label Foreground="Black" FontSize="10" Margin="5,0,0,0" HorizontalAlignment="Left"
VerticalAlignment="Center" Content="Text" />
</Border>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Margin="5,2,0,2">
<Image x:Name="tooltipImage" Width="18" Height="18"
Source=""
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="1" Margin="5,5,5,5">
<TextBlock
Foreground="Black"
Text="Test" FontSize="10"
VerticalAlignment="Center" xml:space="preserve"
HorizontalAlignment="Center"
TextAlignment="Justify" MaxWidth="200"
TextWrapping="Wrap"/>
</Border>
For this border I want the right bottom corner of it to be like it was cutted with a scissor or like a piece of paper that was cutted. I think I need to use Path or some geometry but I don't know exactly how.
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样使用边框的 Clip 属性:
不幸的是,必须给出点的坐标,并且它们的大小不会随边框变化。为了克服这个问题,您可能需要向 Border 添加一个 SizeChanged 事件处理程序,如下所示:
并在处理程序中编写代码,使用 Border 的大小来修改 PathFigure 的点:
You could use the Clip property of the Border like this:
Unfortunately the coordinates of the points must be given and they will not size with the Border. To overcome that you might want to add a SizeChanged event handler to the Border like this:
And write code in the handler that uses the size of the Border to modify the points of the PathFigure: