Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
PieChart dynamic series
posted

Hi, 

I have a control with xamPieCHart on it. 

    <StackPanel>
        <ig:XamPieChart x:Name="_pieChart" ItemsSource="{Binding ChartData}" 
                        ValueMemberPath="Value" LabelMemberPath="Key"
                        HorizontalAlignment="Left" Margin="10,10,0,10" 
                        VerticalAlignment="Top" Height="249" Width="268"
                        BorderBrush="Aqua"
                        BorderThickness="2">
        </ig:XamPieChart>
        <TextBlock Text="{Binding Label}"/>
    </StackPanel>

and this is my ViewModel

    public class PieChartViewModel
    {
        

        public PieChartViewModel()
        {
            Label = "First constructor";
            ChartData = new Dictionary<String, double>();

        }
        public PieChartViewModel(IHydraulicsSnapshotAnalysis analysis, MeasurementUnits units)
        {
            Table = new SnapshotPressureTableViewModel(analysis, units);
        }

        public void UpdateVM()
        {
            ChartData.Add("Item 1", 23);
            ChartData.Add("Item 2", 25);
            ChartData.Add("Something", 11);
            ChartData.Add("BlaBla", 19);
            Label = "Test Biniding on this control";
        }
}

Binding works correctly - When I add some entries to the dictionary then I will get the pie chart no problem. 

What the problem is that when I run UpdateVM() from external class the pie chart on the control wont update. Neither will label. What am I doing wrong here?

Thanks

Michal 

Parents
  • 30890
    Verified Answer
    Offline posted

    Hello Michal,

    I have been investigating into the behavior you are looking to achieve, and I believe this issue is coming from missing interfaces that will update your UI that something has changed. Specifically, the .NET Dictionary class does not implement the INotifyCollectionChanged interface, and so it will not update the UI when updated. You can get around this by setting the XamPieChart.ItemsSource to null and then back to your Dictionary to “force” a refresh. Alternatively, if you were to use a collection type that does implement this by default such as ObservableCollection, the UI update would happen automatically.

    Regarding the Label issue, I believe this is similar in that you likely do not have the INotifyPropertyChanged interface implemented on the Label property. You can read further about this interface here.

    Please let me know if you have any other questions or concerns on this matter.

Reply Children