Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Microsoft.Phone.Controls;
- using PIC.Utils;
- using Microsoft.Phone.Net.NetworkInformation;
- using System.Runtime.Serialization.Json;
- using System.IO;
- using System.Text;
- using System.Windows.Navigation;
- using System.ComponentModel;
- using System.Collections.ObjectModel;
- namespace Paresh.Activities
- {
- public partial class Activities : PhoneApplicationPage
- {
- WebClient client = new WebClient();
- RootPageItem[] items;
- ObservableCollection<RootPageItem> listRootPageItems;
- ObservableCollection<ObservableCollection<RootPageItem>> dataStack;
- public Activities()
- {
- InitializeComponent();
- listRootPageItems = new ObservableCollection<RootPageItem>();
- // listSubPageItems = new List<SubPageItem>();
- dataStack = new ObservableCollection<ObservableCollection<RootPageItem>>();
- if (NetworkInterface.GetIsNetworkAvailable())
- {
- client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
- ProgBar.Visibility = Visibility.Visible;
- client.DownloadStringAsync("webUrl");
- }
- else
- {
- MessageBox.Show("No internet connection!!");
- }
- }
- void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
- {
- if (e.Error != null)
- return;
- else if (e.Error == null && !e.Cancelled)
- {
- ProgBar.Visibility = Visibility.Collapsed;
- String response = GlobalCls.getJsonData(e.Result);
- var ds = new DataContractJsonSerializer(typeof(RootPageItem[]));
- var msnew = new MemoryStream(Encoding.UTF8.GetBytes(response));
- items = (RootPageItem[])ds.ReadObject(msnew);
- RootPageItem item;
- listRootPageItems = new ObservableCollection<RootPageItem>();
- foreach (var ev in items)
- {
- item = new RootPageItem();
- item.Title = HttpUtility.HtmlDecode(ev.Title);
- item.isParent = ev.isParent;
- listRootPageItems.Add(item);
- }
- listBox1.ItemsSource = listRootPageItems;
- }
- }
- /**
- * Making a web call on clicking of an item
- * - If response is with ListBox data, then filling data inside the same ListBox
- * - else display detail data inside WebBrowser
- * */
- private void ListBoxClick(object sender, SelectionChangedEventArgs e)
- {
- if (listBox1.SelectedIndex != -1)
- {
- String title = items[listBox1.SelectedIndex].Title;
- int isParent = Convert.ToInt32(items[listBox1.SelectedIndex].isParent);
- dataStack.Add(listRootPageItems);
- PageTitle.Text = title;
- if (isParent > 0)
- {
- webBrowser1.Visibility = Visibility.Collapsed;
- listBox1.Visibility = Visibility.Visible;
- listBox1.ItemsSource = null;
- Uri webUrl = new Uri("WebURL");
- client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
- ProgBar.Visibility = Visibility.Visible;
- client.DownloadStringAsync(webUrl);
- }
- else
- {
- webBrowser1.Visibility = Visibility.Visible;
- listBox1.Visibility = Visibility.Collapsed;
- String content= items[listBox1.SelectedIndex].content;
- webBrowser1.NavigateToString(HttpUtility.HtmlDecode(content));
- }
- listBox1.SelectedIndex = -1;
- }
- }
- /**
- * 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;
- dataStack.Remove(listRootPageItems);
- e.Cancel = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement