I verified if I wait until after I create the Drawing that setting the pen works fine. So that's what I'm going with.
Setting WPF pen at runtime for System.Windows.Media.GeometryDrawing
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?