Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.76 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Wp7, C# Navigate when download is completed in viewModel
  2. private void DownloadItems()
  3.     {
  4.         string key = this.User.Key;
  5.         WebClient wc = new WebClient();
  6.         wc.DownloadStringCompleted += callback;
  7.         wc.DownloadStringAsync(new Uri("http://localhost/items?key=" + key)); //JSON
  8.     }
  9.        
  10. private void callback(object sender, DownloadStringCompletedEventArgs e)
  11.     {
  12.         if (e.Error == null)
  13.         {
  14.             List<ItemViewModel> col = Deserialize_ItemViewModel(e.Result); // deserialize JSON to List<ItemViewModel>
  15.             this.Items = new ObservableCollection<ItemViewModel>(col);
  16.             ItemDB.Sponsors.InsertAllOnSubmit(col);
  17.             ItemDB.SubmitChanges();
  18.             this.IsDataLoaded = true;
  19.             // ???
  20.         }
  21.     }
  22.        
  23. public class VisibilityConverter : IValueConverter
  24. {
  25.     public object Convert(object value, Type targetType, object parameter,
  26.                CultureInfo culture)
  27.     {
  28.         if (value != null && value is bool && parameter != null)
  29.         {
  30.             var bValue = (bool) value;
  31.             var visibility = (Visibility)Enum.Parse(
  32.             typeof (Visibility), parameter.ToString(),true);
  33.             if (bValue) return visibility;
  34.             return visibility ==
  35.             Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
  36.         }
  37.  
  38.         return null;
  39.     }
  40.  
  41.     public object ConvertBack(object value, Type targetType, object parameter,
  42.                    CultureInfo culture)
  43.     {
  44.          throw new NotImplementedException();
  45.     }
  46. }
  47.        
  48. Visibility="{Binding IsDownloading, Converter={StaticResource VisibilityConverter}, ConverterParameter=Visible}"
  49.        
  50. Dispatcher.BeginInvoke(delegate
  51.  
  52. {
  53.  
  54.  NavigationService.Navigate(new Uri("/Folder/pagename.xaml", UriKind.Relative));
  55.  
  56. });