0

OK, tricky one to explain, but its driving me crazy... Its a UWP App on Windows 10:

I have a main page of which a large part is a Frame (where the main content pages are displayed) on the right is a user control which has a list box in it - when selecting an item in the list it loads the main content page into the frame using a user control event which then calls the Navigate method on the frame - all works fine, except... if you have scrolled down the list then click on an item, the page loads but the listbox scrolls to the top of list - really frustrating!! I can't see why it does this or understand what is going on - can anyone shed some light please?

I know its not reloading the contents and the selecteditem remains selected and does not change.

Wig
  • 11
  • 4
  • Please, if you have problem with the UI layout, post your code. Just basic your description, I'm now guessing that you've navigated from the rootFrame, not the frame for content pages, so will your `ListBox` get refreshed. But without your code? I can't ensure my answer is right. – Grace Feng Jul 21 '16 at 10:24
  • I'm working on simplifying the code so it is more postable - hopefully find the solution in the course of the exercise! – Wig Jul 22 '16 at 07:20
  • OK - I'm still at it. I've come at it from both angles - created a basic project to try and recreate the problem (so far no luck) and also modified my main project to simplify to see if the problem goes away (still no luck) :/ – Wig Jul 22 '16 at 15:01
  • The code is too big to post unfortunately. I've pinpointed other scenarios when it gets triggered, I'll try to explain: The people list is populated by a WCF service which creates an array of objects used as the view model for my listbox - all works fine. It would appear that it is nothing todo with the selection of the listbox because if I navigate to ANY form in the main frame the listbox scrolls to the top and I can't seem to put a breakpoint anywhere, where this happens – Wig Jul 22 '16 at 15:06
  • another thing I've noticed is that even within a loaded page if I page through a pivot control on that page it will make the listbox scroll to the top - very strange. How is this even possible?! – Wig Jul 22 '16 at 15:07
  • [link](http://recordit.co/LQhlcOLdA3) This link shows the listbox on the right, scrolled down a bit, then changed pivot on the main page - if the pivot has controls in it (to or from), then the listbox scrolls to the top - if the pivot is empty - it does not scroll. I assure you there is not code on the pivot changed event :/ – Wig Jul 22 '16 at 15:16
  • Is that possible you upload your project so I can test it? – Grace Feng Jul 23 '16 at 05:15
  • Where would I upload it? – Wig Jul 23 '16 at 11:14
  • Your github or onedrive. – Grace Feng Jul 23 '16 at 15:53
  • OK, I've uploaded it here https://1drv.ms/f/s!AJcVJ2WATz1zpftx Instructions are in the readme - it should be fairly straight forward to getting it running - if you can spot what I'm doing wrong that would be amazing! Thanks – Wig Jul 25 '16 at 11:11

1 Answers1

0

I'm not familiar with Unity, but after some research in your project, I think that each time you select one Item, you reload all your items in ListBox. For example you can take a look at your UserControl named "PersonPicker":

    private void cbCategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (isLoaded)
           people.AddFilterAndOrder("Person Category," + ((ViewModel.SystemConfiguration.SystemData.WorkCategory)cbCategory.SelectedItem).PluralTitle, loadModel: true);
    } 

Then I found your AddFilterAndOrder method in BaseListVM:

    public void AddFilterAndOrder(string filter = "", string order = "", bool loadModel = false)
    {
        if (filter != "")
        {
            string[] items = filter.Split(';');

            foreach (string i in items)
            {
                string[] pair = i.Split(',');

                if (pair[1] == "")
                    filters.Remove(pair[0]);
                else
                    if (filters.Keys.Contains(pair[0]))
                    filters[pair[0]] = pair[1];
                else
                    filters.Add(pair[0], pair[1]);
            }
        }

        if (order != "")
        {
            string[] items = order.Split(';');

            foreach (string i in items)
            {
                string[] pair = i.Split(',');

                if (pair[1] == "")
                    orders.Remove(pair[0]);
                else
                    if (orders.Keys.Contains(pair[0]))
                    orders[pair[0]] = pair[1];
                else
                    orders.Add(pair[0], pair[1]);
            }
        }

        if (loadModel) LoadModel();
    }

Since you passed "loadModel" as true to this method, LoadModel() method will be executed, I won't paste your LoadModel() method here again, but in your LoadModel method, you clear the Items and reload Items again. This is why I said you probably have refreshed your list.

So, maybe you can try:

people.AddFilterAndOrder("Person Category," + ((ViewModel.SystemConfiguration.SystemData.WorkCategory)cbCategory.SelectedItem).PluralTitle, loadModel: false); 

when one Item is selected.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • Thanks for your response. Did you get the project working (its fairly straight forward, if it doesn't you may need to look at the capabilities in your app.manifest)? I tried your suggestion but if I put a break point in the LoadModel method it does NOT get called on selection of an item in the list - yet the list still jumps to the top... The SelectionChanged event you have highlighted is for the category filter drop down which will cause the list to refresh. – Wig Jul 26 '16 at 09:47
  • @Wig, No, your project is too large, I didn't download it, just read the code. I will try to read code again, and if I found problem, I will let you know. So you select Item only using `ListBox_Tapped` event? – Grace Feng Jul 26 '16 at 09:49
  • Yes, the `ListBox_Tapped` is the only place where an item can be selected and fires my ItemSelected which is then caught by the MainPage `PersonPicker_ItemSelected` method, which then navigates the frame. – Wig Jul 26 '16 at 10:56
  • @Wig, I downloaded your project and tried to debug, followed your sweet Readme, but seems I can't really get the WCF service work, it means my service is a mex, not a soap. I've tried to add port profile in cmd line, still didn't work. So I created another sample using your code with fake data, the problem won't be reproduced, I'm sorry, I can't solve this case. Should I delete my answer? – Grace Feng Jul 27 '16 at 03:09
  • Can you try one more thing - in the Unify (uwp) project make sure your manifest capabilities allow: Internet (client & server) and private networks (client & server) - that should make it work if you've the right path for the DB and address for the service as per the readme file - don't give up!! (Thanks for your help tho) – Wig Jul 27 '16 at 07:37
  • @Wig, of course I've ensured those capabilities in the UWP project, and the DB address for service. What I met was this problem: [WCF Service Host Configuration - Please try changing the HTTP port to 8732](http://stackoverflow.com/questions/23521033/wcf-service-host-configuration-please-try-changing-the-http-port-to-8732/23781805), and I tried to run VS as administrator also add http profile in the command line correctly, neither could solve my problem, the service was started as a mex type without network capability, I can't pull any of the data from database. – Grace Feng Jul 27 '16 at 08:46