我试图从正在从数据库中读入的列表添加到可观察集合中,但每当我尝试添加它时,它都会引发错误。我认为这是我添加它的方式,也许我应该添加一些东西/别的地方。 The error I get is 'ChestItems' is a type, which is not valid in the given context
尝试添加到ObservableCollection但出现错误
我试图将项目添加到可观察集合,以便它们可以显示在下拉框中。只是名字。
public sealed partial class MainPage : Page
{
List<Defence> defItems;
List<HeadItems> headItems;
ObservableCollection<HeadItems> headList;
public MainPage()
{
headList = new ObservableCollection<HeadItems>();
headItems = new List<HeadItems>();
this.InitializeComponent();
DataContext = this;
data();
}
async void data()
{
// items read in from database, parsed and saved in an Object here
foreach (var item in defItems)
{
switch (item.armorType.ToString())
{
case "Chest":
chestItems.Add(new ChestItems(item.armorName, item.physicalDefence, item.fireDefence, item.magicDefence, item.lightningDefence, item.poise));
headList.Add(ChestItems); // this is where the error is
break;
}
}
headDropdown.ItemsSource = headList;
}
}
检查结合。值 –
在ObservableCollection中声明属性公开 headList –