[英]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.