问题描述
限时送ChatGPT账号..我有上面的场景:如果用户点击 ListBox,它将有子项(同样是 ListBox)或详细信息视图.
I have above scenario: If user click on ListBox, it will either have sub items (again ListBox) or detail view.
所以我目前所做的是:每当用户单击任何项目时,如果单击的项目有更多子项目,则进行网络调用并填充相同的列表框.
So what i did currently is: Whenever user clicks any item, made a web call and filled up the same ListBox if clicked item is having further sub items.
现在,问题出现了:
假设我在第 4 个屏幕(详细视图),移动到第三个和第二个屏幕,数据保持为堆栈(它工作正常,是的,我在ObservableCollection<ObservableCollection<MyObjects>>
中维护数据,所以在向后移动时,我正在获取数据从那里)现在,如果我单击屏幕 2 中的任何项目,它将打开屏幕 3 列表框数据的详细视图.
Suppose i am in 4th screen (detail view),
Moved to the 3rd and 2nd screen with data maintained as stack (Its working fine, yes i am maintaining data in ObservableCollection<ObservableCollection<MyObjects>>
so while moving back, i am fetching data from there)
Now, if i click any item in screen 2, it will open detail view for the screen 3 ListBox data.
意味着 ListBox 没有收到我们在 OnBackKeyPress()
Means that ListBox is not getting notified that we have filled data inside OnBackKeyPress()
仅供参考,我正在同一页面中填充 ListBox 和 WebBrowser.,所以我的问题是,一旦我从我维护的堆栈中填充了数据,我该如何通知 ListBox?
FYI, i am filling up ListBox and WebBrowser in the same page., so my problem is that how do i notify ListBox once i filled up data from stack which i have maintained?
是的,我也实现了 INotifyPropertyChanged
但不知道为什么它不起作用.
Yes i have also implemented INotifyPropertyChanged
but don't know why its not working.
请检查我的代码:
ListBox 和 WebView 屏幕:http://pastebin/K1G27Yji具有INotifyPropertyChanged
实现的 RootPageItem 类文件:http://pastebin/E0uqLtVG
ListBox and WebView screen: http://pastebin/K1G27Yji
RootPageItem class file with the implementation of INotifyPropertyChanged
: http://pastebin/E0uqLtVG
抱歉以上述方式粘贴代码,我这样做是因为问题很长.
sorry for pasting code in above way, i did as question is being long.
如何通知 ListBox 数据已从 OnBackKeyPress
更改?
How do i notify ListBox that data is changed from OnBackKeyPress
?
推荐答案
糟糕,我犯了一个愚蠢的错误.
Oops it was a silly mistake i made.
我忘记在 OnBackKeyPress() 中设置 items[] 数组,但是在单击 item 时正在访问,因此它具有我们向前移动的最后一步的 items[] 数据,它正在执行相同的数据.
I forgot to set items[] array inside OnBackKeyPress() but was accessing while clicking item, hence its having items[] data of last step we moved in forward direction, it was executing the same data.
现在,我只包含了一行,它解决了我的问题.
Now, i have just included a single line and it has solved my problem.
items = listRootPageItems.ToArray(); // resolution point
所以 onBackKeyPress() 的最终代码是:
So final code of onBackKeyPress() is:
/**
* While moving back, taking data from stack and displayed inside the same ListBox
* */
protected override void OnBackKeyPress(CancelEventArgs e)
{
listBox1.Visibility = Visibility.Visible;
webBrowser1.Visibility = Visibility.Collapsed;
listBox1.SelectedIndex = -1;
if (dataStack.Count != 0)
{
listBox1.ItemsSource = null;
listRootPageItems = dataStack[dataStack.Count-1];
listBox1.ItemsSource = listRootPageItems;
items = listRootPageItems.ToArray(); // resolution point
dataStack.Remove(listRootPageItems);
e.Cancel = true;
}
}
这篇关于Windows Phone 7:如何通知 ListBox 中的数据更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论