I have a WPF ListBox that is set to scroll horizontally. The ItemsSource is bound to an ObservableCollection in my ViewModel class. Every time a new item is added, I want th
This works for me:
DirectoryInfo di = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
foreach (var fi in di.GetFiles("*", SearchOption.AllDirectories))
{
int count = Convert.ToInt32(listBox1.Items.Count); // counts every listbox entry
listBox1.Items.Add(count + " - " + fi.Name); // display entrys
listBox1.TopIndex = count; // scroll to the last entry
}