XAML databinding fejler. ObservableCollection
Jeg har forsøgt at lave en databinding mellem en list<> og en ItemsControlpublic class Year {
public Year() {
MonthList = new MonthList();
}
public Guid CustomerId { get; set; }
public MonthList MonthList { get; set; }
public double Average {
get {
double avg = 0;
foreach( Month month in MonthList )
avg += month.Price;
return avg/12;
}
}
}
itemsControl.ItemsSource = year.MonthList;
<ItemsControl x:Name="itemsControl" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Controls:MonthView ></Controls:MonthView>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Emnerne i listen bliver listet ok men når jeg ændre dem opdateres min property ikke
Her er den type der listes
public class MonthList : ObservableCollection<Month> {
public MonthList():base() {
}
}
public class Month:INotifyPropertyChanged {
public enum Months {
Jan,
Feb,
Mar,
Apr,
Maj,
Jun,
Jul,
Aug,
Sep,
Oct,
Nov,
Dec
}
public Month(Months month) {
Name = month;
Price = 0.43;
}
Months _months;
public Months Name { get { return _months; }
set { _months = value;
NotifyPropertyChanged( "Name" );
}
}
double _price;
public double Price {
get{ return _price;}
set {
_price = value;
NotifyPropertyChanged( "Price" );
}
}
private void NotifyPropertyChanged(String info) {
if( PropertyChanged != null ) {
PropertyChanged( this, new PropertyChangedEventArgs( info ) );
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}