Reputation: 1643
So I have an observable collection that I am updating and I can see the values have changed but the UI is not changing. Here is what I have
public static class GeoLocations
{
public static ObservableCollection<Station> _locations = new ObservableCollection<Station>();
public static ObservableCollection<Station> locations
{
get { return _locations; }
set
{
_locations = value;
}
}
}
public class Station
{
public int StationNumber { get; set; }
// Bunch more properties here ...
}
Then I have a class that is generating random numbers for all the properties in another thread. I know that its changing them because when I hover over the items in the chart I'm using I see it updating. However the chart itself is not updating. Let say that the first number is 1.6. Then updates to 1.4 0.5 1.2... The chart remains at 1.6.
The chart I'm using is an Infragistics XamDataChart. I suspect the problem is the way I've implemented my classes. I have more UI that need to be updated than just the charts so I'm hoping once I figure this out I can make those work here.
Here is my xaml for the XamDataChart
<ig:XamDataChart Style="{StaticResource BarChartStyle}" Grid.Row="1" Grid.Column="1">
<ig:XamDataChart.Axes>
<ig:NumericYAxis x:Name="YAxis" MinimumValue="0" Interval="0.4" Label="{}{}" FontSize="8" MaximumValue="1.7" MajorStroke="#FF2C2C2C" Foreground="White" BorderBrush="White" FontWeight="Bold">
<ig:NumericYAxis.LabelSettings>
<ig:AxisLabelSettings Extent="23" Foreground="White"/>
</ig:NumericYAxis.LabelSettings>
</ig:NumericYAxis>
<ig:CategoryXAxis x:Name="XAxis"
ItemsSource="{Binding}"
Label="{}{IndexNum}"
Interval="1"
MajorStroke="Black"
Foreground="White"
BorderBrush="White"
DataContextChanged="CollectionChanged">
<ig:CategoryXAxis.LabelSettings>
<ig:AxisLabelSettings Extent="17" VerticalAlignment="Bottom" FontSize="11" Foreground="White"/>
</ig:CategoryXAxis.LabelSettings>
</ig:CategoryXAxis>
</ig:XamDataChart.Axes>
<ig:XamDataChart.Series>
<ig:ColumnSeries Style="{StaticResource ColumnSeriesStyle}" x:Name="Series1" ValueMemberPath="StationNumber " XAxis="{Binding ElementName=XAxis}" YAxis="{Binding ElementName=YAxis}" Brush="DodgerBlue" Outline="Black">
</ig:ColumnSeries>
</ig:XamDataChart.Series>
</ig:XamDataChart>
Code Behind
XAxis.ItemsSource = GeoLocations.locations;
Series1.ItemsSource = GeoLocations.locations;
Upvotes: 0
Views: 2751
Reputation: 6683
If the properties are being changed on your Station
objects, you need to implement INotifyPropertyChanged
on it, and fire the PropertyChanged
event in your property setters. It seems like the chart object isn't being notified when your other thread changes the properties. The ObservableCollection
will only cause an update in the chart when Station objects are added or removed, not when their properties change.
You say that when you hover over the chart you see the updated values, but this may be because the chart is actually calling the getter on the property to display that, so you will see the updated value there (but I'm speculating on this).
Upvotes: 4