开发者

WPF: How to set offset to PolyLine

I have 3 Po开发者_StackOverflow中文版lyLines 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.


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> 


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:

WPF: How to set offset to PolyLine

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜