Jump to content
Software FX Community

djsun

Members
  • Posts

    1
  • Joined

  • Last visited

djsun's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I am using 8.0.3712.22025. Here is an example:The Person type has the Name and the Age notify properties. public class Person : INotifyPropertyChanged { private int age; private string name;public Person(string name, int age) { this.name = name;this.age = age; } public event PropertyChangedEventHandler PropertyChanged;public int Age { get{ return this.age; } set{ if (this.age != value) { this.age = value;this.OnPropertyChagned("Age"); } } } public string Name { get{ return this.name; } set{ if (this.name != value) { this.name = value;this.OnPropertyChagned("Name"); } } } protected virtual void OnPropertyChagned(string propName) { var h = this.PropertyChanged;if (h != null) { h(this, new PropertyChangedEventArgs(propName)); } } } The Chart window has a simple chart, a load button to reload the data and a change button to modify the first Person's Age.< Window x:Class="ChartFXWpfApplication1.ChartNotStopListenPropChange" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="480" Width="640" xmlns:cfx="http://schemas.softwarefx.com/chartfx/wpf/80"> <Window.Resources> </Window.Resources><Grid> <cfx:Chart Name="chart1"> <cfx:Chart.AxesX> <cfx:Axis> <cfx:Axis.Title> <cfx:Title Content="Name" /> </cfx:Axis.Title> <cfx:Axis.Labels> <cfx:AxisLabelAttributes BindingPath="Name" /> </cfx:Axis.Labels> </cfx:Axis> </cfx:Chart.AxesX> <cfx:Chart.AxesY> <cfx:Axis> <cfx:Axis.Title> <cfx:Title Content="Age" /> </cfx:Axis.Title> </cfx:Axis> </cfx:Chart.AxesY> </cfx:Chart> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom"> <Button x:Name="Reload" Content="Reload" Click="Reload_Click"/> <Button x:Name="Change" Content="Change" Click="Change_Click"/> </StackPanel></Grid> </ Window>And the code behind: public partial class ChartNotStopListenPropChange : Window{ private Random r = new Random(); private List<Person> source = null;public ChartNotStopListenPropChange() { InitializeComponent(); this.source = new List<Person>(new[] { new Person("Foo", r.Next(1, 100)) });this.load(); } private void AddSeries(IEnumerable<Person> source, Gallery gallery, int? index) { var series1 = new SeriesAttributes(); series1.ItemsSource = source; series1.Gallery = gallery; series1.Content = "Person";series1.BindingPath = "Age"; chart1.Series.Add(series1); } private void Change_Click(object sender, RoutedEventArgs e) { this.source[0].Age += 1; } private void Clear() { foreach (var s in chart1.Series) { s.ItemsSource = null; } chart1.Series.Clear(); chart1.ItemsSource = null; } private void load() { Clear(); AddSeries(this.source, Gallery.Bar, 1); } private void Reload_Click(object sender, RoutedEventArgs e) { this.load(); } } To repro:1. Start the application2. Click the Reload button3. Click the Change buttonAt step 3, NullReferenceException was unhandled.
×
×
  • Create New...