I am trying to display the data points in a ScatterLineSeries when the user clicks a button using the following code:
private void ShowDataPointsButton_Click(object sender, RoutedEventArgs e)
{
foreach (var series in CartesianChart.Series)
{
if (series is ScatterLineSeries)
{
series.DefaultVisualStyle = Application.Current.Resources["DataPointStyle"] as Style;
}
}
}
(where `CartesianChart` is a `RadCartesianChart` control)
The style definition is as follows:
<Style x:Key="DataPointStyle" TargetType="{x:Type Path}">
<Setter Property="Height" Value="5" />
<Setter Property="Width" Value="5" />
</Style>
(I am using a palette to style the chart; hence the missing definition for `Fill`)
But for some reason, I have to follow these steps in order to see the data points styled:
- Press the `ShowDataPointsButton` button
- Zoom into the chart
- Press the `ShowDataPointsButton` button
- Press the `ShowDataPointsButton` button again
I have tried the following options to fix this issue:
- Remove the series from the chart -> Apply the style -> Add the series back into the chart
- Apply the style -> Force a redraw manipulating the zoom level on the chart
- Using the dispatcher associated with the series to force a redraw
- Using Application.Current.Dispatcher to apply the style with Render priority
- Binding a property to `DefaultVisualStyleProperty` and setting its value when user clicks the button
But in all these instances (except option 5 where the trial with binding did not work at all), I have to follow the steps mentioned up above to see the data points in the chart.
Could you please guide me on what is the right way to apply `DefaultVisualStyle` for a ScatterLineSeries in runtime from C# code-behind?