public void ClearIngredients() { if (this.ingredientsView != null) { for (int i = 0; i < this.ingredientItems.Count; i++) { IngredientItem ii = (IngredientItem)this.ingredientsView.GetItemAt(i); ii.ClearIngredients(); ii = null; } this.ingredientItems.Clear(); this.ingredientItems = null; this.ingredientsView = null; this.ingredientsContainer.UpdateLayout(); } }
private void bExpandRecipe_Click(object sender, RoutedEventArgs e) { if (this._isExpanded) { if (this.ingredientsView != null) { for (int i = 0; i < this.ingredientItems.Count; i++) { IngredientItem ii = (IngredientItem)this.ingredientsView.GetItemAt(i); ii.ClearIngredients(); ii = null; } this.ingredientItems.Clear(); this.ingredientItems = null; this.ingredientsView = null; this.ingredientsContainer.UpdateLayout(); } this.tbButtonExpandIngredients.Text = "+"; this.ingredientsContainer.Visibility = System.Windows.Visibility.Collapsed; this.tbRecipeDescription.Visibility = System.Windows.Visibility.Collapsed; } else { this.ingredientItems = new List <IngredientItem>(); this.ingredientsView = new ListCollectionView(this.ingredientItems); this.ingredientsContainer.ItemsSource = this.ingredientsView; this.tbRecipeDescription.Text = String.Format("{0}", this._recipe); this.tbRecipeDescription.Visibility = System.Windows.Visibility.Visible; Array.ForEach <Data.Ingredient>(this._recipe.Ingredients.ToArray(), p => { IngredientItem ii = new IngredientItem(p, _parentWindow, 0); this.ingredientItems.Add(ii); }); this.ingredientsView.Refresh(); this.ingredientsContainer.UpdateLayout(); this.tbButtonExpandIngredients.Text = "-"; this.ingredientsContainer.Visibility = System.Windows.Visibility.Visible; } this._isExpanded = !this._isExpanded; }