PieChart SelectedPoints binding exception

2 posts, 0 answers
  1. Nikolay
    Nikolay avatar
    1 posts
    Member since:
    May 2013

    Posted 10 Mar 2015 Link to this post


    I'm using PieChart with VM-binding and have ArgumentNullException exception in ChartSelectionBehavior.Branch.cs:
    internal void UpdateSelectedPointsAndRaiseSelectionChanged()
                var oldSelectedPoints = this.chart.SelectedPoints; // SelectedPoints is always null
                var newSelectedPoints = this.GetSelectedPoints();
                ////var oldSelectedSeries = this.chart.SelectedSeries;
                ////var newSelectedSeries = this.GetSelectedSeries();
                var addedPoints = newSelectedPoints.Except(oldSelectedPoints).ToList(); //exception here
                var removedPoints = oldSelectedPoints.Except(newSelectedPoints).ToList();

    My XAML:
    <telerik:RadPieChart SelectedPoints="{Binding SelectedPoints}">
            <Style x:Key="PieSliceStyle" TargetType="Path">
                <Setter Property="Fill" Value="{Binding DataItem.Brush}" />
            <telerik:PieChartSmartLabelsStrategy DisplayMode="SpiderAlignedOutwards"/>
            <telerik:ChartSelectionBehavior DataPointSelectionMode="Multiple"
            <telerik:DoughnutSeries ItemsSource="{Binding PieChartErrors}"
                                    DefaultSliceStyle="{StaticResource PieSliceStyle}">
                    <telerik:DataPointLegendSettings TitleBinding="Description"/>

    public class ErrorsAndWarningsViewModel : Page
        private IObservableCollection<PieChartError> _pieChartErrors;
        private ReadOnlyDataPointCollection _selectedPoints;
        public ErrorsAndWarningsViewModel
            PieChartErrors = new BindableCollection<PieChartError>();
            SelectedPoints = new ReadOnlyDataPointCollection();
        public IObservableCollection<PieChartError> PieChartErrors
            get { return _pieChartErrors; }
                if (Equals(value, _pieChartErrors))
                _pieChartErrors = value;
        public ReadOnlyDataPointCollection SelectedPoints
            get { return _selectedPoints; }
                _selectedPoints = value;
        public class PieChartError
            public string Description { get; set; }
            public int Count { get; set; }
            public Brush Brush { get; set; }

    What am I doing wrong?
  2. Martin Ivanov
    Martin Ivanov avatar
    1451 posts

    Posted 12 Mar 2015 Link to this post

    Hi Nikolay,

    The reported exception is thrown because the binding of the SelectedPoints collection kicks in before the setting of the UserControl's DataContext. Therefore, the SelectedPoints collection is not yet created and its value is null. To resolve this you can set the DataContext of the user control before its InitializeComponent() method. Here is an example:
    public MainWindow()
        this.DataContext = new ErrorsAndWarningsViewModel();
    Please try this and let me know if it helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top