嗨,我需要使用 listbox 中的 datateplate 将数据绑定到 listboxx,但我得到了这个:System.Colllections.Generic.List´1[System.String]而不是项目列表。
<ListBox x:Name="lbMenu" ItemsSource="{Binding MyDataForLunchGrid}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="tbMenu" Text="{Binding vydajnaMenus}"/>
<TextBlock x:Name="tbMenuNumber" Text="{Binding vydajnaNumber}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
数据绑定:
_myDataForLunchGrid.Add(new BindingData
{
vydajnaMenus = Vydajna1Menus.Select(s => s.ToString()).ToList(),
vydajnaNumber = "01"
});
OnPropertyChanged("MyDataForLunchGrid");
主页中的 MyCollection
private ObservableCollection<BindingData> _myDataForLunchGrid = new ObservableCollection<BindingData>();
public ObservableCollection<BindingData> MyDataForLunchGrid
{
get { return _myDataForLunchGrid; }
set { _myDataForLunchGrid = value; }
}
类 BindingData
public List<string> vydajnaMenus { get; set; }
public string vydajnaNumber { get; set; }
知道为什么我得到 System.Colllections.Generic.List´1[System.String] 而不是项目列表。?