Setting WPF pen at runtime for System.Windows.Media.GeometryDrawing

Will Pittenger 281 Reputation points
2021-03-27T05:18:16.047+00:00

I have a project with some SVG files in my App's Resources. I retrieve them with the code in the first sample.

if(svgreader == null)
  svgreader =  new SharpVectors.Converters.FileSvgReader(null);

System.IO.Stream stream = typeof(Doc).Assembly.GetManifestResourceStream(strResourceID);
// This returns a System.Windows.DrawingGroup >> svgreader.Read(stream);

Later, I need to set the pen for some System.Windows.Media.GeometryDrawing that don't have the stroke specified in the SVG. This pen is determined by a different file that isn't a resource and won't be known until runtime. I thought the code below would do it once I have the System.Windows.Media.GeometryDrawing created based on the SVG by SharpVectors. (I'm stepping through all the objects in the drawing and duplicating each. This code shows only the part that duplicates the System.Windows.Media.GeometryDrawing`,)

System.Windows.Media.GeometryDrawing geomdrawingNew = new(geomdrawing.Brush, geomdrawing.Pen, geomdrawing.Geometry);

if(geomdrawingNew.Pen == null)
  geomdrawingNew.Pen = new System.Windows.Media.Pen(new System.Windows.Media.SolidColorBrush(rgb), 4);

return geomdrawingNew;

Unfortunately, my new pen doesn't have any effect. I don't understand why. Can someone help?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,676 questions
{count} votes

0 additional answers

Sort by: Most helpful