2015-08-15 72 views
2

我在我的圖表中添加了LineSeries。這裏是代碼:WPF工具包 - 設置線條系列折線顏色與綁定

<chartingToolkit:LineSeries Name="line" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}"> 
    <chartingToolkit:LineSeries.Template> 
     <ControlTemplate TargetType="chartingToolkit:LineSeries"> 
      <Canvas x:Name="PlotArea"> 
       <Polyline x:Name="polyline" 
       Points="{TemplateBinding Points}" 
       Stroke="Green" 
       Style="{TemplateBinding PolylineStyle}" /> 
      </Canvas> 
     </ControlTemplate> 
    </chartingToolkit:LineSeries.Template> 
</chartingToolkit:LineSeries> 

這工作正常。我的折線是綠色的。但是當我嘗試使用綁定設置Polyline.Stroke顏色時,我的線條變得不可見。這裏是代碼:

<chartingToolkit:LineSeries Name="line" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}"> 
    <chartingToolkit:LineSeries.Template> 
     <ControlTemplate TargetType="chartingToolkit:LineSeries"> 
      <Canvas x:Name="PlotArea"> 
       <Polyline x:Name="polyline" 
       Points="{TemplateBinding Points}" 
       Stroke="{Binding Path=MyColor}" 
       Style="{TemplateBinding PolylineStyle}" /> 
      </Canvas> 
     </ControlTemplate> 
    </chartingToolkit:LineSeries.Template> 
</chartingToolkit:LineSeries> 

我無法弄清楚它看起來是什麼問題。

回答

1

你可能使用了錯誤類型的顏色,你應該使用SolidColorBrush

private SolidColorBrush _chartColor = new SolidColorBrush(Colors.Aqua); 
    public SolidColorBrush ChartColor 
    { 
     get 
     { 
      return _chartColor; 
     } 

     set 
     { 
      if (_chartColor == value) 
      { 
       return; 
      } 

      _chartColor = value; 
     } 
    } 

則應該結合工程完全

<chartingToolkit:Chart Title="Line Series" 
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0" > 
     <chartingToolkit:LineSeries Name="line" ItemsSource="{Binding LineSeriesData}" 
      IndependentValueBinding="{Binding Path=Key}" 
      DependentValueBinding="{Binding Path=Value}"> 
      <chartingToolkit:LineSeries.Template> 
       <ControlTemplate TargetType="chartingToolkit:LineSeries"> 
        <Canvas x:Name="PlotArea"> 
         <Polyline x:Name="polyline" 
            Points="{TemplateBinding Points}" 
            Stroke="{Binding ChartColor}" 
            Style="{TemplateBinding PolylineStyle}" /> 
        </Canvas> 
       </ControlTemplate> 
      </chartingToolkit:LineSeries.Template> 

     </chartingToolkit:LineSeries> 
    </chartingToolkit:Chart> 
+0

我用的SolidColorBrush但它不工作... ...嗎你有其他想法嗎? – daidai

+0

我給你的代碼對我來說工作正常,請確保你的「MyColor」不爲空,或者發佈更多的代碼,以便我們找不出問題所在! – Usama

相關問題