I have a class (let's call it externalClass
) with a ObservableCollection<Point> channel1
inside. (the class itself does NOT implements INotify)
In the MainWindow I have a polyline binded to this externalClass.channel1
that uses a converter from ObservableCollection to PointCollection.
So from the C# I bind DataContext = externalClass;
and in the XAML the polyline looks like:
<Polyline Points="{Binding channel1, Converter={StaticResource pointCollectionConverter}}" Stroke="#FF00E100" Name="line" />
I have a test function that works like that:
public void test()
{
ObservableCollection<Point> newone = new ObservableCollection<Point>();
for (int i = 0; i < debugCh1.Count; i++)
{
Point p1 = debugCh1[i];
p1.Y = p1.Y + 1;
newone.Add(p1);
}
channel1= newone;
}
If I add a breakpoint in the converter itself I can see that on start-up it is called (and actually the initial values (hard-coded) are displayed. But when I add the test function to a button .. it does nothing (the converter is not called)
Any idea idea of where the notification of the changes is being stopped ???
SOLUTION
After reading the answers and googleling a bit more I came out with the soulition. Id like to post it there for everybody else
So .. The so-called externalClass must inherit from INotifyPropertyChanged and it must implement NotifyPropertyChanged So all and all it must be declared like that:
public class externalClass : INotifyPropertyChanged
{
....
// at some point you have your ObservableCollection<smth> as a property
public ObservableCollection<Point> channel1 { get; set; }
....
//at some point you implement NotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string caller)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
}
....
//then whenever you need to fire the notification
[..]do something with channel1
NotifyPropertyChanged("channel1");
And that's all. If you add a proper binding (as the one I showed in my question) the whole set up is gonna work.. At least mine worked hehehe
Good luck! And thanks to the people that helped me !! :D
Polyline Points probably does not listen to INotifyCollectionChanged
when bound. Try exposing Channel1
as a property and raise the INotifyPropertyChanged
with "Channel1"