Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:33:51+00:00 2026-06-03T07:33:51+00:00

How can you dynamically update the datasource of a WPF ToolKit chartcontrol? In the

  • 0

How can you dynamically update the datasource of a WPF ToolKit chartcontrol? In the following example I update the TextBlock.Text property succesfully with {Binding SomeText} and setting the DataContext of the MainWindow to the property Input. (Please see the code below)

TextBlock.Text is binded to Input.SomeText and the Chart is suppose to use Input.ValueList as a datasource.

The chart remains empty though. I can fill it once with placing

lineChart.DataContext = Input.ValueList;

in the Main Window constructor and set the binding in XAML to ItemsSource=”{Binding}”. But this only works at startup, it doesn’t update when you click a button for example. I want to update the chart while the application is running with new incoming data.

I have the following XAML:

<chartingToolkit:Chart  Name="lineChart">

                <chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList}">
                </chartingToolkit:LineSeries>

</chartingToolkit:Chart>
<Button Width="100" Height="24" Content="More" Name="Button1" />
<TextBlock Name="TextBlock1" Text="{Binding SomeText}" />

With code:

class MainWindow
{

    public DeviceInput Input;

    public MainWindow()
    {
        InitializeComponent();

        Input = new DeviceInput();
        DataContext = Input;
            lineChart.DataContext = Input;
        Input.SomeText = "Lorem ipsum.";

    }

    private void Button1_Click(System.Object sender, System.Windows.RoutedEventArgs e)
    {
        Input.AddValues();
    }
}

public class DeviceInput : INotifyPropertyChanged
{

    private string _SomeText;
    public string SomeText {
        get { return _SomeText; }

        set {
            _SomeText = value;
            OnPropertyChanged("SomeText");
        }
    }


    public List<KeyValuePair<string, int>> ValueList {get; private set;}

    public DeviceInput()
    {
        ValueList = (new List<KeyValuePair<string, int>>());
        AddValues();
    }

    public void AddValues()
    {
            //add values (code removed for readability)
        SomeText = "Items: " + ValueList.Count.ToString();
        OnPropertyChanged("ValueList");
    }

    public event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged;

    private void OnPropertyChanged(String info)
    {
        if (PropertyChanged != null) {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

}

SomeText gets updated and to make sure the ValueList changes I place ValueList.Count in the textblock and you can see the count rising as it should, however the Chart remains the same.

So this results in 1 succesfull binding (but doesnt update):

lineChart.DataContext = Input.ValueList;

ItemsSource="{Binding}"

This doesn’t bind at all:

ItemsSource="{Binding ValueList}"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:33:52+00:00Added an answer on June 3, 2026 at 7:33 am

    wpf bind to public properties so you need

     public List<KeyValuePair<string, int>> ValueList {get; private set;}
    

    EDIT: here some more information about using the chart control.

    EDIT2:

    ItemsSource="{Binding ValueList}"
    

    this can not work because you have to create ValueList as a property first and second you need to set the datacontext to an instance of DeviceInput (like you did in your mainwindow.cs).

    EDIT3: quick and dirty example, simply copy&paste and if you hit the button data will be added

    viewmodel

    public class Input
    {
        public ObservableCollection<KeyValuePair<string, int>> ValueList { get; private set; }
    
        public Input()
        {
            this.ValueList = new ObservableCollection<KeyValuePair<string, int>>();
            ValueList.Add(new KeyValuePair<string, int>("Developer", 60));
            ValueList.Add(new KeyValuePair<string, int>("Misc", 20));
            ValueList.Add(new KeyValuePair<string, int>("Tester", 50));
            ValueList.Add(new KeyValuePair<string, int>("QA", 30));
            ValueList.Add(new KeyValuePair<string, int>("Project Manager", 40));
        }
    
        public void Add(KeyValuePair<string, int> data)
        {
            ValueList.Add(data);
        }
    }
    

    window.cs

    public partial class MainWindow : Window
    {
      private Input data;
      public MainWindow()
      {
        data= new Input();
        InitializeComponent();
        this.DataContext = data;
      }
    
      private void button1_Click(object sender, RoutedEventArgs e)
      {
        this.data.Add(new KeyValuePair<string, int>("XXX", 27));
      }
    
    }
    

    xaml

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0,-28,0,28">
        <Grid Height="921">
            <chartingToolkit:Chart Height="262" HorizontalAlignment="Left" Margin="33,0,0,620" Name="columnChart" Title="Column Series Demo" VerticalAlignment="Bottom" Width="360">
                <chartingToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList }" />              
            </chartingToolkit:Chart>
            <chartingToolkit:Chart  Name="pieChart" Title="Pie Series Demo" VerticalAlignment="Top" Margin="449,39,43,0" Height="262">
                <chartingToolkit:PieSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList }" IsSelectionEnabled="True" />
            </chartingToolkit:Chart>
            <chartingToolkit:Chart  Name="areaChart" Title="Area Series Demo" VerticalAlignment="Top" Margin="33,330,440,0" Height="262">
                <chartingToolkit:AreaSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList }" IsSelectionEnabled="True"/>
            </chartingToolkit:Chart>
            <chartingToolkit:Chart  Name="barChart" Title="Bar Series Demo" VerticalAlignment="Top" Margin="449,330,43,0" Height="262">
                <chartingToolkit:BarSeries  DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList }" IsSelectionEnabled="True"/>
            </chartingToolkit:Chart>
            <chartingToolkit:Chart  Name="lineChart" Title="Line Series Demo" VerticalAlignment="Top" Margin="33,611,440,0" Height="254">
                <chartingToolkit:LineSeries  DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding ValueList }" IsSelectionEnabled="True"/>
            </chartingToolkit:Chart>
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="342,10,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        </Grid>
    </ScrollViewer>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i update the following JSON object dynamically using javascript or Jquery? var
I have a picture in res/drawable directory: res/drawable/picture.jpeg. Can I dynamically update this picture.jpeg
I am trying to figure out how I can update my sql query dynamically.
All- I am using the TreeMap example of D3 to try and dynamically update
How can I use JFreeChart to dynamically update a chart's appearance after it's been
I'm trying to dynamically update the HTML5 placeholder attribute of a text field using
I have a page where the user can dynamically add file upload boxes. Adding
I am writing a container framework that can dynamically deploy a Jar file containing
Does anyone know how I can Dynamically create an installation package that installs files
The problem in my case is I can dynamically add / remove input boxes,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.