Scroll WPF Listview to specific line

前端 未结 11 1029
孤城傲影
孤城傲影 2020-11-30 02:34

WPF, Browserlike app.
I got one page containing a ListView. After calling a PageFunction I add a line to the ListView, and want to scroll the new line into view:

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 03:04

    I made some changes to Sam's answer. Note that I wanted to scroll to the last line. Unfortunately the ListView sometiems just displayed the last line (even when there were e.g. 100 lines above it), so this is how I fixed that:

        public void ScrollToLastItem()
        {
            if (_mainViewModel.DisplayedList.Count > 0)
            {
                var listView = myListView;
                listView.SelectedItem = listView.Items.GetItemAt(_mainViewModel.DisplayedList.Count - 1);
                listView.ScrollIntoView(listView.Items[0]);
                listView.ScrollIntoView(listView.SelectedItem);
                //item.Focus();
            }
        }
    

    Cheers

提交回复
热议问题