我无法理解如何将我的歌曲数据绑定List<>到 aListBox而无需ItemsSource在后面的代码中设置。它虽然有效,但我真的很想看到列表在 liveview Designer 中工作。
命名空间 App5
{
类 SongsData
{
公共字符串标题 { 获取;放; }
公共字符串歌词 { 获取;放; }
}
}
在我的 MainPage.xaml.cs 中:
公共主页()
{
this.InitializeComponent();
列出歌曲 = new List();
Songs.Add(new SongsData() { Title = "你的歌", Lyrics = "有点好笑.." });
Songs.Add(new SongsData() { Title = "Rocket Man", Lyrics = "I'm the Rocket Maaaan.." });
SongsListBox.ItemsSource = 歌曲;
}
在 XAML 中,我有一个基本的 ListBox:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
一个友好的人可以帮助我了解要改变什么 - 希望是为什么 - 让歌曲标题显示在ListBoxVisual Studio 的实时视图设计器中?
有了上面我必须调试程序才能看到ListBox.
非常感谢。