/
ResultPage.xaml.cs
80 lines (72 loc) · 3.33 KB
/
ResultPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using ODataPad.DataModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Simple.OData.Client;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Item Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234232
namespace ODataPad
{
/// <summary>
/// A page that displays details for a single item within a group while allowing gestures to
/// flip through other items belonging to the same group.
/// </summary>
public sealed partial class ItemDetailPage : ODataPad.Common.LayoutAwarePage
{
public ItemDetailPage()
{
this.InitializeComponent();
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// Allow saved page state to override the initial item to display
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
var itemId = navigationParameter.ToString();
var item = DataSource.Instance.GetItem(navigationParameter.ToString());
this.DefaultViewModel["Item"] = item;
this.DefaultViewModel["ItemElements"] = item.Elements;
var serviceItem = DataSource.Instance.GetItem(itemId.Split('/').First());
var odataClient = new ODataClient(serviceItem.Subtitle);
var results = (odataClient.FindEntries(itemId.Split('/').Last()).Take(10));
foreach (var key in results.First().Keys)
{
this.gridResult.ColumnDefinitions.Add(new ColumnDefinition());
}
for (int index = 0; index < results.Count(); index++)
{
this.gridResult.RowDefinitions.Add(new RowDefinition());
}
this.DefaultViewModel["QueryResults"] = results.Select(x => x.Values.ToArray());
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
protected override void SaveState(Dictionary<String, Object> pageState)
{
}
}
}