【发布时间】:2013-01-08 19:52:51
【问题描述】:
我无法理解如何将我的歌曲List<> 数据绑定到ListBox,而无需在后面的代码中设置ItemsSource。
虽然它可以工作,但我真的很想在 liveview Designer 中看到 List 工作。
在我的 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>
请友好的人帮助我了解要更改哪些内容 - 希望是为什么 - 让歌曲标题显示在 Visual Studio 的实时视图设计器中的 ListBox 中?
有了上面我必须调试程序才能看到ListBox中的歌名。
非常感谢。
【问题讨论】:
标签: c# wpf visual-studio-2010 visual-studio xaml