Dobrý den, Mam graf, kde kazda LineSeries ma jiný PolylineStyle(jinou barvu a čárkování - StrokeDashArray). Problem je, že v legende grafu nevidím jaky je styl te čáry, protoze se nezobrazuje čara. Vytvoril jsem si proto vlastní styl pro LegendItem, jen nevim jak mu predat v kodu hodnotu StrokeDashArray. xaml:
<Style x:Key="DashedLegendItem" TargetType="chartingToolkit:LegendItem">
<Setter Property="Foreground" Value="#FF000000" />
<Setter Property="Padding" Value="5,0,5,0" />
<Setter Property="Margin" Value="0,3,0,2" />
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:LegendItem">
<Grid x:Name="PART_MainContainer" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Line Name="MyLine" />
<TextBlock Grid.Column="1"
Padding="{TemplateBinding Padding}"
Margin="{TemplateBinding Margin}"
Foreground="Black"
Text="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
protected void CreateSeriesStyles(LineSeries series, int stylepor)
{
//Create line style
Style style = new Style(typeof(Polyline));
Setter st = new Setter(Polyline.StrokeDashArrayProperty, this.lineStyle[stylepor]);
style.Setters.Add(st);
series.PolylineStyle = style;
//create datapoint style
style = new Style { TargetType = typeof(LineDataPoint), BasedOn = this.Resources["DataPoinWDesc"] as Style };
SolidColorBrush brush = colorGenerator.GetNextBrush();
style.Setters.Add(new Setter { Property = Control.BackgroundProperty, Value = brush });
series.DataPointStyle = style;
//create legend item style
style = new Style { TargetType = typeof(LegendItem), BasedOn = this.Resources["DashedLegendItem"] as Style };
style.Setters.Add(new Setter(LegendItem.ForegroundProperty, brush));
//nastaveni Line.StrokeDashArray
series.LegendItemStyle = style;
}
Vedel by nekdo jak na to? Diky.
|