public RecipeDisplaySmall(Recipe rcp) : this() { InitializeComponent(); this.DataContext = rcp; _prepTimeLabel.Content = TimeStringFormat.GenerateString(rcp.Time); switch (rcp.Difficulty) { case 3: _difficultyImage.Source = new BitmapImage(new Uri("/images/expertDifficulty.png", UriKind.Relative)); break; case 2: _difficultyImage.Source = new BitmapImage(new Uri("/images/hardDifficulty.png", UriKind.Relative)); break; case 1: _difficultyImage.Source = new BitmapImage(new Uri("/images/mediumDifficulty.png", UriKind.Relative)); break; default: _difficultyImage.Source = new BitmapImage(new Uri("/images/easyDifficulty.png", UriKind.Relative)); break; } }
public RecipeDisplayContent(InitRecipes init, Recipe rcp) : this() { InitializeComponent(); this.DataContext = rcp; this.NewRate = rcp; if (init.FavoriteRecipes.Contains(rcp)) { _favoriteImage.Source = new BitmapImage(new Uri("/images/unfavoriteButton.png", UriKind.Relative)); } foreach ((Ingredient, double)ingredient in rcp.recipeIngredients) { ingredientTextDisplay ingredientDisplay = new ingredientTextDisplay(); ingredientDisplay.IngNameTag = ingredient.Item1.IngredientName; ingredientDisplay.IngNumTag = ingredient.Item2.ToString(); ingredientDisplay.IngMeasureTag = ingredient.Item1.BaseMeasure; this.IngredientsPanel.Children.Add(ingredientDisplay); } switch (this.NewRate.Difficulty) { case 3: _difficultyImage.Source = new BitmapImage(new Uri("/images/expertDifficulty.png", UriKind.Relative)); break; case 2: _difficultyImage.Source = new BitmapImage(new Uri("/images/hardDifficulty.png", UriKind.Relative)); break; case 1: _difficultyImage.Source = new BitmapImage(new Uri("/images/mediumDifficulty.png", UriKind.Relative)); break; default: _difficultyImage.Source = new BitmapImage(new Uri("/images/easyDifficulty.png", UriKind.Relative)); break; } recipeDisplayContent_favoriteButton.Click += (sender, eventArgs) => { if (init.FavoriteRecipes.Contains(rcp)) //If the recipe is already a favorite and the button is clicked to unfavorite { _favoriteImage.Source = new BitmapImage(new Uri("/images/favoriteButton.png", UriKind.Relative)); init.FavoriteRecipes.Remove(rcp); } else //If the image should be added to favorites { _favoriteImage.Source = new BitmapImage(new Uri("/images/unfavoriteButton.png", UriKind.Relative)); init.FavoriteRecipes.Add(rcp); } }; _prepTimeLabel.Content = TimeStringFormat.GenerateString(rcp.Time); }