private void AddRecipeToTree(Recipe recipe) { bool isExist = false; TreeViewItem typeItem = null; foreach (TreeViewItem ti in _root.Items) { if (Equals(ti.Header, recipe.Type)) { isExist = true; typeItem = ti; break; } } if (!isExist) { typeItem = new TreeViewItem {Header = recipe.Type, IsExpanded = true}; _root.Items.Add(typeItem); _typeList.Add(recipe.Type); } var rec = new TreeViewItem {Header = recipe.Name}; rec.MouseDoubleClick += RecipeDoubleClicked; typeItem.Items.Add(rec); SortElementsInNode(_root); SortElementsInNode(typeItem); }
/// <summary> /// The constructor of the class. /// </summary> /// <param name="score">Тhe score of the rating.</param> /// <param name="recipe">The rated recipe.</param> public Rating(double score, Recipe recipe) { this.Score = score; this.Recipe = recipe; }
private void ShowInStack(Recipe recipe) { stack.Children.Clear(); stack.Children.Add(new Label { FontWeight = FontWeights.Bold, FontSize = 20, Foreground = Brushes.Green, HorizontalContentAlignment = HorizontalAlignment.Center, Content = recipe.Name }); stack.Children.Add(new Label { Foreground = Brushes.White, Content = recipe.Type }); foreach (Ingridient ingridient in recipe.Ingridients) { stack.Children.Add(new Label { FontWeight = FontWeights.Thin, HorizontalContentAlignment = HorizontalAlignment.Right, Content = ingridient.Ingr + " " + ingridient.Col + " " + ingridient.Ed }); } stack.Children.Add(new TextBlock { Foreground = Brushes.White, Text = recipe.Text, TextWrapping = TextWrapping.Wrap, }); stack.UpdateLayout(); _curShowIndex = _recipeList.IndexOf(recipe); }
private void ReadRecipeFromXml(string fileName) { var recipe = new Recipe {FileName = fileName}; var ingr = new Ingridient(); var reader = new XmlTextReader(fileName); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { string value = reader.Value; switch (reader.Name) { case ("Name"): recipe.Name = value; break; case ("Type"): recipe.Type = value; break; case ("Text"): recipe.Text = value; break; case ("Ingr"): ingr = new Ingridient {Ingr = value}; break; case ("Col"): ingr.Col = value; break; case ("Ed"): ingr.Ed = value; recipe.Ingridients.Add(ingr); break; } } } } reader.Close(); AddRecipeToTree(recipe); _recipeList.Add(recipe); }