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 Juick.Classes; using Microsoft.Phone.Controls; namespace Juick { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); // Set the data context of the listbox control to the sample data DataContext = App.ViewModel; Loaded += MainPage_Loaded; } // Load data for the ViewModel MyFeed private void MainPage_Loaded(object sender, RoutedEventArgs e) { if (!App.ViewModel.IsDataLoaded) { if (string.IsNullOrEmpty(App.Account.Credentials.UserName)) NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative)); else App.ViewModel.LoadData(); } } private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { // If selected index is -1 (no selection) do nothing if (((ListBox)sender).SelectedIndex == -1) return; // Navigate to the new page NavigationService.Navigate(new Uri("/ThreadView.xaml?mid=" + App.ViewModel.MyFeed[((ListBox)sender).SelectedIndex].MID, UriKind.Relative)); // Reset selected index to -1 (no selection) ((ListBox)sender).SelectedIndex = -1; } private void LastBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { // If selected index is -1 (no selection) do nothing if (((ListBox)sender).SelectedIndex == -1) return; // Navigate to the new page NavigationService.Navigate(new Uri(string.Format("/ThreadView.xaml?mid={0}&last=true", App.ViewModel.Last[((ListBox)sender).SelectedIndex].MID), UriKind.Relative)); // Reset selected index to -1 (no selection) ((ListBox)sender).SelectedIndex = -1; } public static string GetInlineList(TextBlock element) { if (element != null) return element.GetValue(InlineList) as string; return string.Empty; } public static void SetInlineList(TextBlock element, string value) { if (element != null) element.SetValue(InlineList, value); } public static readonly DependencyProperty InlineList = DependencyProperty.RegisterAttached( "InlineList", typeof(List), typeof(MainPage), new PropertyMetadata(null, OnInlineListPropertyChanged)); private static void OnInlineListPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var tb = obj as TextBlock; if (tb != null) { // clear previous inlines tb.Inlines.Clear(); // add new inlines var inlines = e.NewValue as List; if (inlines != null) { inlines.ForEach(inl => tb.Inlines.Add((inl))); } } } private void ApplicationBarIconButtonClick(object sender, EventArgs e) { App.ViewModel.MyFeed.Clear(); App.ViewModel.Last.Clear(); App.ViewModel.LoadData(); } private void ApplicationBarMenuItemClick(object sender, EventArgs e) { App.Account.SignOut(this); } private void ApplicationBarIconButtonClick1(object sender, EventArgs e) { NavigationService.Navigate(new Uri("/NewPostView.xaml", UriKind.Relative)); } } }