Visual Studio のテンプレートに基づいた GroupedItemsPage を使用しています。SampleDataSource が提供されているので、それを例として使用し、独自のデータ ソースを作成しました。ただし、インターネットから非同期的にダウンロードされるアイテムをグリッド ビューに追加したいと考えています。問題は、結果を取得して処理し、データ ソースに追加すると、画面が更新されず、新しいグリッド ページが表示されないことです。
LoadState
GroupedItemsPage クラスのメソッドは次のとおりです。
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Create an appropriate data model for your problem domain to replace the sample data
var h = DataModel.MainPageDataSource.GetSingleton().GetGridGroups("AllGroups");
this.DefaultViewModel["Groups"] = h;
}
ここに私のデータソースクラスがあります:
class MainPageDataSource : FacepunchWin8.Common.BindableBase
{
public static MainPageDataSource _singleton = new MainPageDataSource();
public static MainPageDataSource GetSingleton() { return _singleton; }
private static Uri _baseUri = new Uri("ms-appx:///");
private ObservableCollection<MainPageGrid> _gridGroups = new ObservableCollection<MainPageGrid>();
void IndexParserComplete(HTMLParser p)
{
HTMLParserIndex parser = p as HTMLParserIndex;
foreach (ForumSection f in parser.GetForumSections())
{
MainPageGrid forumGrid = new MainPageGrid(f.Title(), f.Title());
_gridGroups.Add(forumGrid);
}
}
private void ItemsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
}
public MainPageDataSource()
{
HTMLParserIndex parser = new HTMLParserIndex();
parser.SetComplateDelegate(IndexParserComplete);
Scraper.GetSingleton().RequestForumIndex(parser);
MainPageGrid Grid1 = new MainPageGrid("GRID1", "TestPage");
Grid1.Items.Add(new MainPageGridItem("Grid00", "GridOne", "Subtitle", "Assets/DarkGray.png"));
_gridGroups.Add(Grid1);
}
public ObservableCollection<MainPageGrid> GetGridGroups(string uniqueId)
{
if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");
return _gridGroups;
}
}
SampleDataSource
コンストラクターは、画面に正しく表示される によく似たアイテムをいくつか作成します。ただし、データがインターネットからダウンロードされた後、IndexParserComplete
が呼び出され、新しいアイテムが _gridGroups に追加されます。GroupedItemsPage に通知して画面を更新し、データ ソースからデータを再読み込みするにはどうすればよいですか?