gpt4 book ai didi

wpf - 在 WPF 中创建填充图案

转载 作者:行者123 更新时间:2023-12-03 21:15:39 26 4
gpt4 key购买 nike

我能够在 WPF 中创建条纹图案,但是如何在 XAML 中创建这样的图案? WPF 中是否有默认的类似画笔?

enter image description here

最佳答案

您可以使用 VisualBrush 在 XAML 中执行此操作.您只需要为 Path 指定数据值。 , 例如:

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

enter image description here

用于转换 Image到矢量图形(路径)使用 Inkscape ,这是免费的,非常有用。有关更多信息,请参阅此链接:

Vectorize Bitmaps to XAML using Potrace and Inkscape

Edit

为了获得更好的性能,您可以 Freeze()您在 PresentationOptions 的帮助下刷牙像这样:
<Window x:Class="MyNamespace.MainWindow"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" ...>

<VisualBrush x:Key="MyVisualBrush" PresentationOptions:Freeze="True" ... />

引自 MSDN :

When you no longer need to modify a freezable, freezing it provides performance benefits. If you were to freeze the brush in this example, the graphics system would no longer need to monitor it for changes. The graphics system can also make other optimizations, because it knows the brush won't change.

关于wpf - 在 WPF 中创建填充图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22919296/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com