Windows Phone 7:如何通知 ListBox 中的数据更新?

编程入门 行业动态 更新时间:2024-10-28 16:18:19
本文介绍了Windows Phone 7:如何通知 ListBox 中的数据更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-25 15:53:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1118552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   数据   Windows   Phone   ListBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!