简体   繁体   English

UWP-在同一页面的框架中浏览后,列表框滚动到顶部

[英]UWP - Listbox scrolls to top after navigating within a frame on the same page

OK, tricky one to explain, but its driving me crazy... Its a UWP App on Windows 10: 好的,棘手的人可以解释一下,但是它使我发疯……Windows 10上的UWP应用:

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!! 我有一个主页,其中很大一部分是框架(显示主要内容页面),右边是一个用户控件,其中带有一个列表框-在列表中选择一个项目时,它将加载主要内容页面使用用户控制事件进入框架,然后该事件在框架上调用Navigate方法-一切正常,除非...如果您向下滚动列表然后单击某个项目,则页面会加载,但列表框会滚动到页面顶部列表-真令人沮丧! 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. 我知道它不会重新加载内容,并且selecteditem保持选中状态并且不会更改。

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 . 我对Unity不熟悉,但是在对项目进行研究后,我认为每次选择一个Item时,都将所有项目重新加载到ListBox For example you can take a look at your UserControl named "PersonPicker": 例如,您可以查看名为“ PersonPicker”的UserControl

    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 : 然后我在BaseListVM找到了您的AddFilterAndOrder方法:

    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. 由于您将“ loadModel”作为真实值传递给此方法, LoadModel()将执行LoadModel()方法,因此我不会在此处再次粘贴您的LoadModel()方法,但是在您的LoadModel方法中,您将清除Items并重新加载Items。 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. 当选择一项时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用按钮浏览同一页面中的div标签? - Navigating from div tags within the same page using buttons? 从 Page1.xaml 导航到 Page2.xaml。 UWP xaml。 没有为此对象定义无参数构造函数。 Frame.Navigate 带参数 - Navigating from Page1.xaml to Page2.xaml. UWP xaml. No parameterless constructor defined for this object. Frame.Navigate with parameters 返回框架后如何在UWP C#中重新填充列表框? - How to re-populate listbox in UWP C# after returning to the frame? 从另一个页面返回后,UWP无法在文本框中设置文本 - UWP cannot set the text in a textbox after navigating back from another page 导航并返回页面后,获取背景音频的当前播放时间-UWP - Get current playback time of background audio after navigating away and back to the page - UWP 导航回到其他页面(UWP,模板10) - Navigating back to different page (UWP, Template 10) 时间轴中的UWP UserActivity无法导航到单击的正确页面 - UWP UserActivity in Timeline not navigating to correct page on click 单击列表框中的项目导航到新页面 - navigating to a new page on clicking an item in the listbox 在UWP中导航后,AdControl停止更新 - AdControl stops updating after navigating back in UWP 在UWP中的帧(SplitView)中导航时丢失了DataContext - Lost DataContext when navigating back in Frame (SplitView) in UWP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM