我想在我的线图中添加点数,但它不会在视觉上改变。我第一次点击按钮就会增加两点。每次其他点击什么都不做,为什么不呢?
C#代码:
List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
private void Button_Click_3(object sender, System.Windows.RoutedEventArgs e)
{
valueList.Add(new KeyValuePair<string, int>(DateTime.Now.ToString("T"), 130));
System.Threading.Thread.Sleep(1000);
valueList.Add(new KeyValuePair<string, int>(DateTime.Now.ToString("T"), 140));
lineSeries1.ItemsSource = valueList;
}
XAML:
<chartingToolkit:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" Width="400" Height="250" Background="LightSteelBlue">
<chartingToolkit:Chart.Series>
<chartingToolkit:LineSeries x:Name="lineSeries1" Title="Test" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}">
</chartingToolkit:LineSeries>
</chartingToolkit:Chart.Series>
</chartingToolkit:Chart>
答案 0 :(得分:0)
使用ObservableCollection而不是List。
ObservableCollection<KeyValuePair<string, int>> valueList =
new ObservableCollection<KeyValuePair<string, int>>();