Scroll WPF Listview to specific line

前端 未结 11 995
孤城傲影
孤城傲影 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:00

    Thanks for that last tip Sam. I had a dialog which opened, meaning my grid lost focus every time the dialog closed. I use this:

    if(currentRow >= 0 && currentRow < lstGrid.Items.Count) {
        lstGrid.SelectedIndex = currentRow;
        lstGrid.ScrollIntoView(lstGrid.SelectedItem);
        if(shouldFocusGrid) {
            ListViewItem item = lstGrid.ItemContainerGenerator.ContainerFromItem(lstGrid.SelectedItem) as ListViewItem;
            item.Focus();
        }
    } else if(shouldFocusGrid) {
        lstGrid.Focus();
    }
    

提交回复
热议问题