private void ToolsForTransactionWindow_OnLoaded(object sender, RoutedEventArgs e) { _collectionViewSource = this.FindResource("ListView") as CollectionViewSource; var toolsList = TransactionType == TransactionType.Rent ? _db.GetToolsForTransaction(TransactionType.Return) : _db.GetToolsForTransaction(TransactionType.Rent); if (toolsList.Count == 0) { switch (TransactionType) { case TransactionType.Rent: MessageBox.Show("Nie ma nic do wypożyczenia", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information); break; case TransactionType.Return: MessageBox.Show("Nie ma nic do zwrotu", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information); break; } this.Close(); } if (TempList.Any()) { foreach (var tool in TempList) { toolsList.Remove(tool); } } this.DataContext = toolsList; }