1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using WpfApplication2.Annotations;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : INotifyPropertyChanged
{
private List<KeyValuePair<string, int>> _dataList;
public List<KeyValuePair<string, int>> DataList
{
get { return _dataList; }
set
{
if (Equals(value, _dataList)) return;
_dataList = value;
OnPropertyChanged("DataList");
}
}
public MainWindow()
{
InitializeComponent();
showColumnChart();
}
private void showColumnChart()
{
List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
valueList.Add(new KeyValuePair<string, int>("Developer", 100));
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));
DataContext = this;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
var list = new List<KeyValuePair<string, int>>();
foreach (KeyValuePair<string, int> pair in DataList)
{
list.Add(new KeyValuePair<string, int>(pair.Key, pair.Value + 5)); // simulation d'un changement de données
}
DataList = list;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
} |
Partager