使用PNG(透明)图像和背景颜色创建自定义刷子
-
09-10-2019 - |
题
我想在WPF中创建一个自定义刷子,该刷子将应用于矩形。填充= mycustombrush。 Thecustombrush包含PNG图像(ImageBrush),并在背景中含有颜色(SolidColorbrush)。我想用这两个标准刷创建一个CustomBrush。
感谢帮助。
解决方案
您可以使用VisualBrush。例子
<SolidColorBrush x:Key="MyBackgroundColor" Color="Green"/>
<VisualBrush x:Key="RectangleBrush">
<VisualBrush.Visual>
<Grid>
<Rectangle Fill="{StaticResource MyBackgroundColor}"/>
<Image Source="BackgroundImageSource"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
<!-- ... -->
<Rectangle Fill="{StaticResource RectangleBrush}"/>
不隶属于 StackOverflow