Ejemplo n.º 1
0
        public ICollectionView FilterView(Kind kind, ICollectionView view)
        {
            view.Filter = o =>
            {
                var entry = ((KeyValuePair <string, Entry>)o).Value;

                return(entry.Data.Kind == kind &&
                       (ShowZeroes || entry.Count > 0) &&
                       (!ShowOnlyForFavorites || favoritedBlueprints.Any(b => b.Ingredients.Any(i => i.Entry == entry))));
            };

            PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == nameof(ShowZeroes) || e.PropertyName == nameof(ShowOnlyForFavorites))
                {
                    view.Refresh();
                }
            };

            Blueprints.ForEach(b => b.PropertyChanged += (o, e) =>
            {
                if (ShowOnlyForFavorites && e.PropertyName == "Favorite")
                {
                    Application.Current.Dispatcher.Invoke(view.Refresh);
                }
            });

            return(view);
        }
Ejemplo n.º 2
0
        public ICollectionView FilterView(MainWindowViewModel parentViewModel, Kind kind, CollectionViewSource source)
        {
            source.Filter += (o, e) =>
            {
                var entry = ((KeyValuePair<string, Entry>)e.Item).Value;

                e.Accepted = entry.Data.Kind == kind &&
                       (parentViewModel.ShowZeroes || entry.Count > 0) &&
                       (!parentViewModel.ShowOnlyForFavorites || favoritedBlueprints.Any(b => b.Ingredients.Any(i => i.Entry == entry)));
            };

            parentViewModel.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == nameof(parentViewModel.ShowZeroes) || e.PropertyName == nameof(parentViewModel.ShowOnlyForFavorites))
                {
                    source.View.Refresh();
                }
            };

            Blueprints.ForEach(b => b.PropertyChanged += (o, e) =>
            {
                if (parentViewModel.ShowOnlyForFavorites && e.PropertyName == "Favorite")
                {
                    Application.Current.Dispatcher.Invoke(source.View.Refresh);
                }
            });

            return source.View;
        }