I have problem binding ObservableCollection to LisView. The problem is that Binding works fine only when I add/remove item from ObservableCollection. But when I change property of one item in ObservableCollection the ListView still shows old value. I know it's a common problem and searched for a solution and everybody say that I should use BindingList instead of ObservableCollectione because ObservableCollection does not propagate PropertyChanged events and BindingList does. So I changed to Binding List but the problem remains the same.
Class:
public class Network
{
public class Layer : INotifyPropertyChanged
{
public enum ActivFunction { LINEAR, EXPONENTIAL, ARCUSTANGENT }
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
RaisePropertyChanged("Name");
}
}
public ActivFunction Activation { get; set; }
public int Neurons { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(String propertyName)
{
if ((PropertyChanged != null))
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public BindingList<Layer> Layers { get; set; }
public Network()
{
Layers = new BindingList<Layer>();
}
public void AddLayer(Layer layer)
{
if (Layers.Count > 0)
{
int last = Layers.Count;
Layers.Last().Name = "Layer " + last + " (hidden)";
}
Layers.Add(layer);
}
public void RemoveLayer(int index)
{
if( index >= 0 && index < Layers.Count )
Layers.RemoveAt(index);
}
}
Binding:
<ListView Grid.Row="0" x:Name="NetworkListview" ItemsSource="{Binding network.Layers}"
IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="layer name"
DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Width="60" Header="neurons"
CellTemplate="{StaticResource NeuronsTemplate}"/>
<GridViewColumn Width="110" Header="activation"
CellTemplate="{StaticResource ActivationTemplate}"/>
</GridView>
</ListView.View>
</ListView>