我试图在ListBox项的成分与另一个列表匹配时更改ListBox项的名称及其标签内容。这是我的解决方案,但不起作用。
public void changeSciName()
{
foreach (var recipe in RecipeList)
{
bool equalIngredients = recipe.Recipe.All(selectedPotion.MyIngredients.Contains) && recipe.Recipe.Count == selectedPotion.MyIngredients.Count;
if (equalIngredients)
{
selectedPotion.Name = recipe.RecipeName;
scientificNameLabel.Content = recipe.RecipeName;
RefreshPotionListBox();
}
}
}
void RefreshPotionListBox()
{
potionListBox .Items.Clear();
foreach (var item in potionNames)
{
potionListBox.Items.Add(item);
}
}