I'm beginner and I tried to search everywhere for a similar problem, this question has been asked many times but I couldn't find any solution.
I implemented INotifyPropertyChanged
like this (it is working correctly):
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
MessageBox.Show("property changed");
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
My observablecollection
look like this :
ObservableCollection<bool> Test = new ObservableCollection<bool>(new[] { false, false, false, false, false, false });
private ObservableCollection<bool> _Collection;
public ObservableCollection<bool> Collection
{
get { return _Collection = Test; }
set { _Collection = value; OnPropertyChanged("Collection"); }
}
This collection is bound to togglebutton's property contained in usercontrols :
VidFlipX="{Binding DataContext.Collection[1], ElementName=cmix, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Data changed correctly while using them but if I set the collection in an other way, OnPropertyChanged
is not firing and so my togglebuttons are not updated.
Can't find out why...