在 WPF 中的单个 GeometryDrawing 中使用多个画笔
是否可以在单个 几何绘图
?我想用不同的画笔绘制几个几何图形,并且必须为每个几何图形声明一个单独的 GeometryDrawing
,这是相当冗长的。我正在寻找一种更简洁的方式来表达以下内容:
<DrawingImage x:Key="SomeDrawingImage">
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="{StaticResource SomeGradient}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="{StaticResource SomeFigures}">
<PathGeometry.Transform>
<TransformGroup>
<TranslateTransform X="50" />
</TransformGroup>
</PathGeometry.Transform>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="{StaticResource SomeOtherGradient}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="{StaticResource SomeOtherFigures}">
<PathGeometry.Transform>
<TransformGroup>
<TranslateTransform X="100" />
</TransformGroup>
</PathGeometry.Transform>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
Is it possible to use multiple brushes within a single GeometryDrawing
? I have several geometries that I want to draw with different brushes, and it's rather verbose to have to declare an individual GeometryDrawing
for each. I'm looking for a more concise way to express the following:
<DrawingImage x:Key="SomeDrawingImage">
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="{StaticResource SomeGradient}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="{StaticResource SomeFigures}">
<PathGeometry.Transform>
<TransformGroup>
<TranslateTransform X="50" />
</TransformGroup>
</PathGeometry.Transform>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="{StaticResource SomeOtherGradient}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="{StaticResource SomeOtherFigures}">
<PathGeometry.Transform>
<TransformGroup>
<TranslateTransform X="100" />
</TransformGroup>
</PathGeometry.Transform>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我了解您的问题,我想说在单个 GeometryDrawing 中不可能有多个画笔。
GeometryDrawing 的全部目的是将笔画(使用 Pen 属性)和填充(使用 Brush 属性)...与几何图形(使用 Geometry 属性)结合起来。
为了使我们的 xaml 更加简洁,我们自己不仅共享画笔(这是常见的),而且还共享几何形状......但您的 xaml 表明您也在做同样的事情。
In as far as I understand your question, I would say it is not possible to have multiple brushes within a single GeometryDrawing.
The whole purpose of a GeometryDrawing is to combine a stroke (with the Pen property) and a fill (with the Brush property) ... with a geometry (with the Geometry property).
To make our xaml more concise, we ourselves have shared not only brushes (which is common) but also geometry ... but your xaml suggests that you are doing the same.
你可以在后面的代码中做到这一点
you can do that in code behind
使用 GeometryDrawing 时,您始终可以覆盖画笔的资源:
You can always overwrite the resources of the brushes when you use the GeometryDrawing:
您可以使用视觉画笔来实现这一点
You can use a visualbrush to achieve that