Hello,
I have a VisualBrush and need this VisualBrush as a Drawing. Anyone knows how this can be done? Thanks for any hint!
Hello,
I have a VisualBrush and need this VisualBrush as a Drawing. Anyone knows how this can be done? Thanks for any hint!
Your question doesn't really make sense, because a VisualBrush
is unrelated to a Drawing
(it would make more sense with a DrawingBrush
). However, you can create a Drawing
by using the VisualBrush
to paint on it. Something like that should work :
public static Drawing GetDrawing(TileBrush brush)
{
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawRectangle(brush, new Pen(Brushes.Transparent, 0.0), brush.ViewPort);
drawingContext.Close();
return drawingVisual.Drawing;
}
(this is valid for any brush inherited from TileBrush
, not just a VisualBrush
)
Here's the XAML version:
<GeometryDrawing Geometry="M0,0 L1,0 1,1 0,1 Z">
<GeometryDrawing.Brush>
<VisualBrush>
...
</VisualBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>