locked
WPF Scroll-bar is not working properly RRS feed

  • Question

  • In my WPF application i have multiple data-list tables each contains many items. When i scroll down to see the items it works but scroll gets reset when the focus is lost. I am not sure if i should try to save the state of scroll bar because i don't want to save the state of scroll bar when the application gets restarted. 
    Tuesday, October 6, 2015 6:40 AM

Answers

  • The first thing to mention is that putting many items in any itemscontrol is a bad way to work for the user.

    Many items means they have to spend their working time scrolling.

    If at all possible, you should arrange it so the user only every has a maximum of a couple of hundred items in any itemscontrol.

    Use some filtering mechanism like a treeview or combobox etc so the user can pick only the data he wants to read.

    Nobody can read thousands of rows of data.

    .

    On to your particular problem.

    You've  not explained anywhere near enough here.

    Like any sort of a clue as to why the scroll would be reset when the focus is lost.

    Because if you just set focus to some other control than a listbox or datagrid, that does not reset where the datagrid is scrolled to.

    Don't do whatever that is.

    Here's one guess.

    If these are say in pages with a page per tab in a tabcontrol then when you navigate away and back, the page in the tab will be re-instantiated. You can avoid that by seting page.KeepAlive=true

    https://msdn.microsoft.com/en-us/library/system.windows.controls.page.keepalive%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Hope that helps.

    Technet articles: WPF: MVVM Step 1; All my Technet Articles

    Tuesday, October 6, 2015 6:14 PM

All replies

  • Without any XAML we would just be guessing.

    Lloyd Sheen

    Tuesday, October 6, 2015 4:41 PM
  • The first thing to mention is that putting many items in any itemscontrol is a bad way to work for the user.

    Many items means they have to spend their working time scrolling.

    If at all possible, you should arrange it so the user only every has a maximum of a couple of hundred items in any itemscontrol.

    Use some filtering mechanism like a treeview or combobox etc so the user can pick only the data he wants to read.

    Nobody can read thousands of rows of data.

    .

    On to your particular problem.

    You've  not explained anywhere near enough here.

    Like any sort of a clue as to why the scroll would be reset when the focus is lost.

    Because if you just set focus to some other control than a listbox or datagrid, that does not reset where the datagrid is scrolled to.

    Don't do whatever that is.

    Here's one guess.

    If these are say in pages with a page per tab in a tabcontrol then when you navigate away and back, the page in the tab will be re-instantiated. You can avoid that by seting page.KeepAlive=true

    https://msdn.microsoft.com/en-us/library/system.windows.controls.page.keepalive%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Hope that helps.

    Technet articles: WPF: MVVM Step 1; All my Technet Articles

    Tuesday, October 6, 2015 6:14 PM