views:

44

answers:

1

I have a path shape that I would like to combine lines that have different line thicknesses? The StrokeThickness property is set on the Path object so I cannot change it for different lines. This same issue would arise if I wanted to change my line color.

The reason I want to do this is so that I can draw an arrowhead. Charles Petzold arrowheads http://www.charlespetzold.com/blog/2007/04/191200.html don't work for me. If my line is dashed the closed arrowhead draws weirdly.

I figured a way to do it was to combine at the end of my path/line a new short line geometry that was thicker than the my original path/line and had TriangleLineCap, voila, got myself an arrowhead. But I can't combine geometries that have different line thicknesses and dashed types, etc.

Any ideas?

A: 

Just use multiple Path objects in a panel like a Canvas or a Grid where they will draw on top of each other:

<Grid>
    <Path Stroke="Blue" StrokeThickness="2">
        <Path.Data>
            <EllipseGeometry Center="20 20" RadiusX="10" RadiusY="10" />
        </Path.Data>
    </Path>
    <Path Stroke="Green" StrokeThickness="1" StrokeDashArray="1 2">
        <Path.Data>
            <LineGeometry StartPoint="10 20" EndPoint="30 20"/>
        </Path.Data>
    </Path>
</Grid>
Quartermeister
I am doing this programmatically not using XAMAL. I am building a diagram display application (Visio-like) and all my shapes are WPF Shapes that are added to one main canvas. I was kinda' hoping not to mix adding Shapes and mini-canvases.
@zfeld: `Shape.OnRender` makes a single call to `DrawingContext.DrawGeometry`, so it can only ever use a single Brush and Pen. You could wrap *every* diagram in a mini-canvas, even if it's only a single WPF Shape, and then at least you won't have a mix.
Quartermeister
How about overriding the OnRender() method? Is that an option? How would I make a custom Shape object that would be made up of 2 Shape objects and then in the overridden OnRender() method somehow I have the DrawingContext draw the geometries of the 2 shapes and switch the pen between drawing? Does this approach make sense?
@zfeld: You could certainly implement a custom UIElement that draws two geometries in OnRender. You would probably need to override MeasureOverride and ArrangeOverride as well to get the correct layout. I would still recommend having a Panel with two Shape children and letting the framework figure it all out, but if that doesn't work in your application then overriding OnRender is a good approach.
Quartermeister