I’m having trouble understanding how to databind my Songs List<> to a ListBox without needing to set the ItemsSource in the code behind.
It works though, but I would really like to see the List working in the liveview Designer.
namespace App5
{
class SongsData
{
public string Title { get; set; }
public string Lyrics { get; set; }
}
}
And in my MainPage.xaml.cs:
public MainPage()
{
this.InitializeComponent();
List Songs = new List();
Songs.Add(new SongsData() { Title = "Your Song", Lyrics = "It's a little bit funny.." });
Songs.Add(new SongsData() { Title = "Rocket Man", Lyrics = "I'm the Rocket Maaaan.." });
SongsListBox.ItemsSource = Songs;
}
And in the XAML I have a basic ListBox:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Can a friendly person please help me understand what to change – and hopefully why – to get the songs title to show in the ListBox in the liveview Designer of Visual Studio?
With the above I have to Debug the program to see the song titles in the ListBox.
Many thanks in advanced.
You basically need to apply the DesignData build time action to your data files. A very comprehensive walkthrough can be found at msdn.