I'm to write out a text file in a ListBox, but all I'm getting is a list "BabyName". My code looks like this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void FirstDecadeTopNames_Loaded(object sender, RoutedEventArgs e)
{
FileStream fs = new FileStream(@"D:\Dokumenter\Skole\6. semester\GUI\Exercises\Exercise4\WpfApplication1\04-babynames.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs, Encoding.Default);
List<BabyName> babyNames = new List<BabyName>();
while (!sr.EndOfStream)
{
BabyName name = new BabyName(sr.ReadLine());
babyNames.Add(name);
FirstDecadeTopNames.Items.Add(name);
}
}
}
I assume I'm not putting the StreamReader into my list, but I can't see where I'm doing it wrong.
Update:
Here's the XAML for the ListBox:
<ListBox Name="FirstDecadeTopNames"
Margin="10"
Loaded="FirstDecadeTopNames_Loaded" >
</ListBox>