views:

57

answers:

3

I have 3 PolyLines that have same geometry.

I would like to set offset to two of them, so they would appear right next to each other.

How can i do that?

thanx.

+1  A: 

That depends on the container you are using. If you use Grid (with no rows or colums) or canvas, they are directly on top of each other. You can space them apart by means of Margin (grid) or Left/Top (canvas).

Or use a different Panel, like Stackpanel, that arranges them next to each other automatically.

Edit: In the comments, we developed the idea of using a LinearGradientBrush to color a single Geometry, like this:

<Polyline StrokeThickness="20" Points="30,250 200,250">
    <Polyline.Stroke> 
        <LinearGradientBrush StartPoint="30,200" EndPoint="30,250" MappingMode="Absolute"> 
            <GradientStop Color="Red" Offset="1" /> 
            <GradientStop Color="Red" Offset="0.66" /> 
            <GradientStop Color="Yellow" Offset="0.66" /> 
            <GradientStop Color="Yellow" Offset="0.33" /> 
            <GradientStop Color="Green" Offset="0.33" /> 
            <GradientStop Color="Green" Offset="0" /> 
        </LinearGradientBrush> 
   </Polyline.Stroke> 

Jens
i have tried that, but see the image (http://www.shrani.si/f/2A/13v/LJSLWsW/test.png) with my problem ...
no9
@no9: I don't know how it should look. =) If you want them to form the same geometry, but thicker and striped, I don't think that you can use the same geometry for all three stripes.
Jens
is there really no way to draw the polyline with an offset?
no9
what im doing is drawing a map. So for instance ... i have several polylines with same geonetry (in reality they are cables in the same shaft). So i need to draw them one next to eachother (rainbow style). Any suggestions (besides using different styles for them like thickness and opacity) how i could offset them? Im not looking to offset the lines using their container, but rather offset the drawing itself (Pen?)... hop i make sense...
no9
maybe an idea ... forget that there are two PolyLines ... can i just draw 1 PolyLine with some sort of styling (like holding two pens of different color in hand when drawing a line)
no9
@no9: Maybe use a LinearGradientBrush for the Pen?
Jens
jens: with this code i have 1 color missing: " <Polyline StrokeThickness="20" Points="30,250 200,250"> <Polyline.Stroke> <LinearGradientBrush StartPoint="30,200" EndPoint="30,250" MappingMode="Absolute"> <GradientStop Color="Red" Offset="1" /> <GradientStop Color="Yellow" Offset="1" /> <GradientStop Color="Green" Offset="1" /> </LinearGradientBrush> </Polyline.Stroke> </Polyline>"
no9
@no9: You need to set different offsets for the colors to show. See my edited answer.
Jens
thanx jens, but that works only for streight lines. If i would want to apply that to complex polyline i have a bigger problem. I have created a solution using System.Drawing.Pen and applying CompoundArray to it. Its working fine for me and i will use it for my WPF app. Yes i have asked my question wrong so i thank all of you for your time spending on it.
no9
A: 

You should explain in what container your polylines are set. In general I would use a RenderTransform.

Mart
can u point me to some good example?
no9
+1  A: 

I think I understood your exact need: you wish to draw polylines like on a road map, where multiple lines follow the same path but always keep the same distance between them.

This is a much more complicated problem. There is an excellent article by Key Johnson where he creates geometric visual brushes: Stacked Geometry Brush Factory.

An example of what he manages to do: alt text

Mart