Articles in this section
Category / Section

How to change the series selection when clicking the legend items in WPF Chart?

1 min read

You can change the Interior of a Series when its LegendItem is clicked using the MouseDown event of ChartLegend and get the series of corresponding LegendItem from the MouseButtonEventArgs.

 

This KB article explains how to get a Series from its corresponding LegendItem.

 

XAML:

 
   <chart:SfChart.Legend>
         <chart:ChartLegend MouseDown="ChartLegend_MouseDown"/>
   </chart:SfChart.Legend>
 

 

C#:

    
    public partial class MainWindow : Window
    {
        private ChartSeriesBase prevSeries;
        private void ChartLegend_MouseDown(object sender, MouseButtonEventArgs e)
        {       …
                if (series != null)
                {
                    if (prevSeries != series && prevSeries != null)
                        prevSeries.Interior = null;
 
                    if (series.Interior == null)
                        series.Interior = new SolidColorBrush(Colors.Red);
                    else
                        series.Interior = null;
 
                    prevSeries = series;
                }
        }
    }
 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied