Я могу добавлять значения (я могу прочитать их в отладчике), но представление не обновляется.
Я уже многое перепробовал, но, кажется, ничто не решает эту проблему.
Надеюсь, вы сможете помочь
Вот мой код:
private ObservableCollection transactions = new ObservableCollection();
public ObservableCollection Transactions
{
get { return transactions; }
set
{
transactions = value;
OnNotifyPropertyChanged();
}
}
public class Transaction:BaseViewModel
{
private string name = null;
private string price = null;
private double numPrice = 0;
private string date = null;
public string Name
{
get
{
return name;
}
set
{
OnNotifyPropertyChanged();
name = value;
}
}
public string Price
{
get
{
return price;
}
set
{
OnNotifyPropertyChanged();
price = value;
}
}
public double NumPrice
{
get
{
return numPrice;
}
set
{
OnNotifyPropertyChanged();
numPrice = value;
}
}
public string DateTime
{
get
{
return date;
}
set
{
OnNotifyPropertyChanged();
date = value;
}
}
}
Моя BaseViewModel:
public class BaseViewModel : INotifyPropertyChanged
{
protected BaseViewModel()
{
}
#region Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
protected void OnNotifyPropertyChanged([CallerMemberName] string memberName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(memberName));
}
}
}
В XAML:
Заранее спасибо
Редактировать:
Вот как я обновляю коллекцию:
public void AddTransaction(string name, double price, DateTime dateTime)
{
Transactions.Add(new Transaction()
{
Name = name,
Price = ($"-{price}€".Replace('.',',')),
NumPrice = price,
DateTime = dateTime.ToString("dd.MM.yyyy")
});
}
Подробнее здесь: https://stackoverflow.com/questions/739 ... i-do-wrong
Мобильная версия