【发布时间】:2015-10-22 11:15:49
【问题描述】:
我有图表。
我使用一些自定义模板设置所有点的样式:
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True">
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="{x:Type chartingToolkit:LineDataPoint}">
<Setter Property="Background" Value="#bdb3ce" />
<Setter Property="Foreground" Value="#bdb3ce" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:LineDataPoint">
<Canvas>
<Ellipse Height="8" Width="8" StrokeThickness="2" Stroke="#bdb3ce" Fill="#423852"/>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</chartingToolkit:LineSeries>
在使用Template 之前,可以单击图表上的点使其“活跃”(点变为红色)。
应用模板后如何使点激活?
模板代码之前:
<chartingToolkit:Chart Grid.Row="1" Grid.ColumnSpan="2" Name="lineChart" VerticalAlignment="Top" Height="200">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X">
<chartingToolkit:LinearAxis.MajorTickMarkStyle>
<Style TargetType="Line">
<Setter Property="Stroke" Value="White" />
<Setter Property="StrokeThickness" Value="1" />
<Setter Property="Y1" Value="-4" />
<Setter Property="Y2" Value="4" />
</Style>
</chartingToolkit:LinearAxis.MajorTickMarkStyle>
</chartingToolkit:LinearAxis>
<chartingToolkit:LinearAxis Orientation="Y">
<chartingToolkit:LinearAxis.MajorTickMarkStyle>
<Style TargetType="Line">
<Setter Property="Stroke" Value="White" />
<Setter Property="StrokeThickness" Value="1" />
<Setter Property="Y1" Value="-4" />
<Setter Property="Y2" Value="4" />
</Style>
</chartingToolkit:LinearAxis.MajorTickMarkStyle>
</chartingToolkit:LinearAxis>
</chartingToolkit:Chart.Axes>
<chartingToolkit:Chart.Style>
<Style TargetType="Control">
<Setter Property="Foreground" Value="White" />
</Style>
</chartingToolkit:Chart.Style>
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0" />
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.PlotAreaStyle>
<Style TargetType="Grid">
<Setter Property="Background" Value="Transparent" />
</Style>
</chartingToolkit:Chart.PlotAreaStyle>
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True">
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="{x:Type chartingToolkit:LineDataPoint}">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="White" />
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
【问题讨论】:
-
@jstreet,请看code-before
标签: c# wpf templates charts wpftoolkit