In my application, I have a ListBox with items. The application is written in WPF.
How can I scroll automatically to the last added item? I want the
For me, the simplest working way was this: (without Binding)
private void WriteMessage(string message, Brush color, ListView lv)
{
Dispatcher.BeginInvoke(new Action(delegate
{
ListViewItem ls = new ListViewItem
{
Foreground = color,
Content = message
};
lv.Items.Add(ls);
lv.ScrollIntoView(lv.Items[lv.Items.Count - 1]);
}));
}
Don't need to create classes or change the xaml, just write the messages with this method and it scroll automatically.
Calling just
myLv.Items.Add(ls);
myLv.ScrollIntoView(lv.Items[lv.Items.Count - 1]);
for exemple, don't work for me.