是否可以动态更改PolyLine.strokeThickness值?

时间:2017-03-04 22:21:53

标签: c# wpf polyline

我正在写一个地图制作程序,我有一个非常好的效果,当用户绘制它时,河流的宽度会动态变化:

enter image description here

当您画河时,您可以看到宽度增加和减少。这是代码:

   Point TempP = new Point();
                Point TempPBottom = new Point();

                int ChangeRiverSize = 0;
                int HowMuch = 0;

                ChangeRiverSize = rnd.Next(1, 11);
                if (ChangeRiverSize == 1)
                {
                    HowMuch = rnd.Next(1, 3);
                }

                polyLine.Stroke = System.Windows.Media.Brushes.LightBlue;
                if (HowMuch == 1)
                    RiverWidth--;
                else if (HowMuch == 2)
                    RiverWidth++;

                polyLine.StrokeThickness = RiverWidth;

                TopPolyLine.Stroke = new SolidColorBrush(Colors.CornflowerBlue);
                TopPolyLine.StrokeThickness = 2;

                BottomPolyLine.Stroke = new SolidColorBrush(Colors.CornflowerBlue);
                BottomPolyLine.StrokeThickness = 1;

                currentPoint = e.GetPosition(MainCanvas);
                TempP = currentPoint;
                TempP.Y = TempP.Y - (RiverWidth / 2);

                TempPBottom = currentPoint;
                TempPBottom.Y = TempPBottom.Y + (RiverWidth / 2);

                polygonPoints.Add(currentPoint);
                TopPolygonPoints.Add(TempP);
                BottomPolygonPoints.Add(TempPBottom);

                polyLine.Points = polygonPoints;
                TopPolyLine.Points = TopPolygonPoints;
                BottomPolyLine.Points = BottomPolygonPoints;

问题在于当用户放开鼠标按钮时,似乎河流回到了均匀的宽度。然而,这两个河岸进出的事实愚弄了眼睛。

我认为折线只能在整个线条长度上有一个宽度。反正有吗?

1 个答案:

答案 0 :(得分:0)

  

我认为折线只能在整个线条长度上有一个宽度。反正有吗?

不,你必须使用填充区域。