1

If I have a rather meandering Path in my WPF app, is there a way I can make it appear as two differently-colored Paths of identical widths side-by-side? I'd rather not try to hand-code the whole thing again with slightly different values. I thought of using a Brush, but the list of Brushes doesn't appear to have one such.

Edit: I want a Path divided sharply by color, even if it curves, like this:

elbow turn, half green and half red

Lyndon Gingerich
  • 604
  • 7
  • 17
  • 2
    Could you add a small image of what you are trying to obtain, not sure I understood. Maybe is something as `LinearGradientBrush` you are looking for? – Siegfried.V Nov 01 '22 at 16:15
  • 1
    Ok, so I have no idea if such a thing is possible "at once". I did something similar for another application (in my case, I have a distance between the 2 lines, but you could put distance = thickness of line). I made a function `MoveToRight`, then I drew all my pathes with a parallel line. If nobody answers or have a better idea, this would make the deal. – Siegfried.V Nov 01 '22 at 17:30
  • @Siegfried.V Interesting idea! I was trying to do something similar by drawing two identical lines and setting one's top margin and the other's bottom margin negative. Maybe I could make a function `MoveOutward`. – Lyndon Gingerich Nov 01 '22 at 17:47
  • As for me, I worked from `Contour` class I made, with X1, X2, Y1, Y2, Radius if needed. So having a List, in order to have a clean result, you even can calculate intersections of parallel lines. Then there is a little bit of mathematics for the function, but nothing so difficult. – Siegfried.V Nov 01 '22 at 17:51
  • Oh, wow. I like that. We'll see. I'm also trying something with a scaled duplicate. – Lyndon Gingerich Nov 01 '22 at 19:01

2 Answers2

0

Made a little search, and found that also :

Two-color Path object

Timwi answer :

<StackPanel Orientation="Horizontal">
    <StackPanel.LayoutTransform>
        <ScaleTransform CenterX="0" CenterY="0" ScaleX="15" ScaleY="15" />
    </StackPanel.LayoutTransform>

    <Grid Margin="-5,0,0,0">
        <Path Fill="Blue" Stroke="Transparent">
            <Path.Data>
                <PathGeometry>M10,10 C20,10 10,20 20,20 L20,19 C11,19 21,9 10,9</PathGeometry>
                <!--          |←    original path    →| |←  generated part   →| -->
            </Path.Data>
        </Path>
        <Path Fill="Red" Stroke="Transparent">
            <Path.Data>
                <PathGeometry>M10,10 C20,10 10,20 20,20 L20,21 C9,21 19,11 10,11</PathGeometry>
                <!--          |←    original path    →| |←   generated part   →| -->
            </Path.Data>
        </Path>
    </Grid>
</StackPanel>

So "playing" with margin may be much easier that the other options I told you about for what you need.

Siegfried.V
  • 1,508
  • 1
  • 16
  • 34
0

DropShadowEffect solved my issue.

Lyndon Gingerich
  • 604
  • 7
  • 17