0

I've been this for a while now but I can't seem to be figuring out why my code won't update the window. The events are called and the invoke methods are invoked, but still, my window won't update

 public class RaceContext : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public Race CurrentRace { get; set; }
    public string TrackName { get => CurrentRace == null ? "" : "Track name : " + CurrentRace.Track.Name; }
    public List<IParticipant> Participants { get; set; }

    public ObservableCollection<DriverListView> DriverListViews
    {
        get { return _DriverListViews; }
        set { _DriverListViews = value; OnPropertyChanged(nameof(DriverListViews)); }
    }
    public ObservableCollection<DriverListView> _DriverListViews = new ObservableCollection<DriverListView>();

    public void OnNextRace(object sender, NextRaceEventArgs e)
    {
        CurrentRace = e.Race;
        e.Race.DriverChanged += OndriversChanged;
        e.Race.DriverMoved += OnDriverMoved;
        DriverListViews = new ObservableCollection<DriverListView>();
        CurrentRace.Participants.ForEach(item =>
        {
            DriverListViews.Add(new DriverListView()
            {
                Driver = item
            });
        });
        OnPropertyChanged();
    }

    public void OndriversChanged (object sender, DriversChangedEventArgs e)
    {
        Participants = CurrentRace.Participants;
        e.DriverTimers.ForEach(timer =>
        {
            var view = DriverListViews.Where(item => item.Driver.Equals(timer.Driver)).First();
            view.RaceStopwatch = timer.TotalRaceTimer.Elapsed;
            view.LapStopwatch = timer.LapTimer.Elapsed;
        });

        OnPropertyChanged(nameof(DriverListViews));
    }

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

This is the list view class

 public class DriverListView
{
    public IParticipant Driver { get; set; }
    public int Position { get; set; }
    public TimeSpan RaceStopwatch { get; set; }
    public int LapCount { get; set; }
    public TimeSpan LapStopwatch { get; set; }
    public string LapPercentage { get; set; }
    public int SectionCount { get; set; }
    public string ParticipantName { get => Driver.Name; }
    public TeamColors TeamColor { get => Driver.TeamColor; }
    public int ParticpantPoints { get => Driver.Points; }

}

So when OnDriverChanged is called, the INotifyPropertyChanged is called. the window does not update the records Thanks

  • `OnPropertyChanged(nameof(DriverListViews))` has no effect since no new value was assigned to the DriverListViews property. The change notification is ignored. `view.RaceStopwatch = timer.TotalRaceTimer.Elapsed;` etc has no effect because DriverListView does not implement INotifyPropertyChanged. – Clemens Jan 25 '22 at 18:30
  • Calling OnPropertyChanged() in OnNextRace does not make any sense at all. – Clemens Jan 25 '22 at 18:32

0 Answers0