Я получаю нулевое значение PropertyChanged из-за создания нового класса _Date, который поможет в процессе игры.Как я могу отправить значения в XAML и сохранить класс _Date.Необходимо обновить currentMoney и currentPolution.Если я обновлю в MainWindow.xaml.cs эти 2 свойства все в порядке.Но из _Date PropertyChanged имеет значение NULL.
public class _Date : ViewModelBase {
private DateTime today;
private DateTime destinationDay;
private Polutions.Pollution.Pollution pollution = MainWindow.currentPollution;
private Money.Money money = MainWindow.currentMoney;
public DateTime Today {
get => today;
set {
today = value;
OnPropertyChanged(nameof(Today));
}
}
// Property for count of simulation days
public int DayCount { get; set; }
public _Date() {
today = DateTime.Today;
destinationDay = new DateTime();
pollution = new Polutions.Pollution.Pollution();
money = new Money.Money();
}
//Simulation of game process
//TODO:
/*
Problem: Don't displaying changing of pollution + money
Possible solution: Delete _Date class, probably because of it PropertyChanged NULL!
*/
public void startSimulation() {
destinationDay = today;
destinationDay = destinationDay.AddDays(DayCount);
for (; Today.Date < destinationDay.Date; Today = Today.AddDays(1)) {
pollution.CurrentPollution += 0.1;
money.CurrentMoney -= 1000;
DayCount--;
}
}
}
MainWindow.xaml.cs
public partial class MainWindow : Window {
public static Money currentMoney;
public static Pollution currentPollution;
public static _Date date;
public MainWindow () {
InitializeComponent();
currentMoney = new Money();
currentPollution = new Pollution();
date = new _Date();
CurrentMoney.DataContext = currentMoney;
CurrentPollution.DataContext = currentPollution;
StartDateLabel.DataContext = date;
}
private void Initialize() {
Facktories.Content = Facktories.Content.ToString() + FactoriesList.Quantity;
FactoriesPollution.Content = FactoriesPollution.Content.ToString() + FactoriesList.FullPolution;
}
private void Window_ContentRendered(object sender, EventArgs e) {
Initialize();
}
private void Button_Click(object sender, RoutedEventArgs e) {
date.DayCount = Convert.ToInt32(DayCountBox.Text);
date.startSimulation();
}
}