0

for steps in []IronPython WPF アプリケーション内で Polyline() を使用して、ループの非常に単純な例を作成しようとしています。ループの反復ごとに異なる色を描画する必要がありますが、Brushes は定義済みの System.Windows.Media.SolidColorBrush オブジェクトのセットを実装しています。変数を交換Redする方法がわかりません。steps

def polylineShape(self):

    x = self.myCanvas.Width/2
    y = self.myCanvas.Height/2
    polyline = Polyline()
    polyline.StrokeThickness = 5


    for steps in ['Red','Blue','Green','Black']:
        x = x
        y = x            
        polyline.Points.Add(Point(x,y))
        x = x + 40
        polyline.Points.Add(Point(x,y))
        polyline.Stroke = Brushes.Red        #change colour on iteration

    self.myCanvas.Children.Add(polyline)
4

1 に答える 1

0

試行錯誤して解決策を作成しましたが、ブラシ型に直接色を渡す方法がわかりませんでした。

def polylineShape(self):
    x = 0
    y = 0

    for steps in [Brushes.SteelBlue, Brushes.DarkOrange, Brushes.DarkSeaGreen, Brushes.Honeydew]:
        polyline = Polyline()                                           
        polyline.StrokeThickness = self.myCanvas.Height/4               
        x = 0                                                           
        y = y + self.myCanvas.Height/4                                  
        polyline.Points.Add(Point(x,y))                                 

        x = self.myCanvas.Width                                         
        polyline.Points.Add(Point(x,y))                                 

        polyline.Stroke = steps                                         

        self.myCanvas.Children.Add(polyline)
于 2015-10-30T00:53:07.817 に答える