2012-08-13 57 views

回答

3

我搜索了Silverlight Toolkit製圖組件的類似解決方案,並找到this

幸運的是,事實證明,相同的方法可以在WPF中應用。通過將屬性LineSeries.PolylineStyle設置爲具有合適的Shape.StrokeDashArray屬性設置的System.Windows.Shapes.Polyline樣式,可以獲得期望的行破折號。

編程,它可以像這樣的東西來完成:

var series = new LineSeries 
    { 
     ItemsSource = calcData, 
     IndependentValuePath = "X", 
     DependentValuePath = "Y", 
     PolylineStyle = GetDashedLineStyle() 
    }; 

... 

Style GetDashedLineStyle() 
{ 
    var style = new Style(typeof(Polyline)); 
    style.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, 
         new DoubleCollection(new[] { 5.0 }))); 
    return style; 
} 
+1

有用 - 感謝您的回答自己的問題!我也用這個[link](http://www.java2s.com/Tutorial/CSharp/0470__Windows-Presentation-Foundation/RoundStrokeDashCapPolyline.htm) – tdc 2014-10-09 21:05:05

+0

經過3個小時的搜索找到了這個。謝謝..從上述 引用的鏈接複製 < chartingToolkit:LineSeries.PolylineStyle> <形式的TargetType = 「折線」> JenonD 2015-04-08 04:58:18

0

另一種方式來增加在WPF XAML到:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 

... 


    <Window.Resources> 
     <Style x:Key="DashedPolyLine" TargetType="{x:Type Polyline}">       
      <Setter Property="StrokeDashArray" Value="2 3 2" /> 
     </Style>   
    </Window.Resources> 

... 

<chartingToolkit:LineSeries Title="Title" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding BindingValue}" PolylineStyle="{StaticResource DashedPolyLine}"/> 
相關問題