问题描述
我能够在 WPF 中创建条纹图案,但是如何在 XAML 中创建这样的图案?WPF 中是否有默认类似的画笔?
您可以在 XAML 中使用 ,这是免费的并且非常有用.有关更多信息,请参阅此链接:
使用 Potrace 将位图矢量化为 XAML和 Inkscape
编辑
为了获得更好的性能,您可以 Freeze()
在 PresentationOptions
像这样:
引用自 MSDN
:
当您不再需要修改 freezable 时,冻结它可以提供性能优势.如果您在本例中冻结画笔,图形系统将不再需要监视它的变化.图形系统还可以进行其他优化,因为它知道画笔不会改变.
I was able to create stripe patterns in WPF, but how can I create a pattern like this in XAML? Is there a default similar brush for this in WPF?
You can do it in XAML using VisualBrush
. You only need to specify Data values for the Path
, for example:
XAML
<Window.Resources>
<VisualBrush x:Key="MyVisualBrush" TileMode="Tile" Viewport="0,0,15,15" ViewportUnits="Absolute" Viewbox="0,0,15,15" ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Grid Background="Black">
<Path Data="M 0 15 L 15 0" Stroke="Gray" />
<Path Data="M 0 0 L 15 15" Stroke="Gray" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Window.Resources>
<Grid Background="{StaticResource MyVisualBrush}">
<Label Content="TEST" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
Output
For converting Image
to Vector graphics (Path) use Inkscape
, which is free and very useful. For more information see this link:
Vectorize Bitmaps to XAML using Potrace and Inkscape
Edit
For better performance, you may Freeze()
you Brushes with help of PresentationOptions
like this:
<Window x:Class="MyNamespace.MainWindow"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" ...>
<VisualBrush x:Key="MyVisualBrush" PresentationOptions:Freeze="True" ... />
Quote from MSDN
:
这篇关于在 WPF 中创建填充图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!