private void EvaluateTile(TileViewModel tile) { var currentDay = _userData.Configuration.CurrentDay; if (tile.Days[currentDay]) { if (!TileViews.Any(v => v.DataContext == tile)) { var tileView = tile.CreateTileView(); TileViews.Add(tileView); } } else { if (TileViews.Any(v => v.DataContext == tile)) { var view = TileViews.First(v => v.DataContext == tile); TileViews.Remove(view); } } }
private void TilesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (TileViewModel tile in e.NewItems) { tile.PropertyChanged += TileDayPropertyChanged; EvaluateTile(tile); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (TileViewModel tile in e.OldItems) { if (TileViews.Any(v => v.DataContext == tile)) { var view = TileViews.First(v => v.DataContext == tile); TileViews.Remove(view); } tile.PropertyChanged -= TileDayPropertyChanged; } } }