
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
None | size: 1.76 KB | hits: 11 | expires: Never
Wp7, C# Navigate when download is completed in viewModel
private void DownloadItems()
{
string key = this.User.Key;
WebClient wc = new WebClient();
wc.DownloadStringCompleted += callback;
wc.DownloadStringAsync(new Uri("http://localhost/items?key=" + key)); //JSON
}
private void callback(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
List<ItemViewModel> col = Deserialize_ItemViewModel(e.Result); // deserialize JSON to List<ItemViewModel>
this.Items = new ObservableCollection<ItemViewModel>(col);
ItemDB.Sponsors.InsertAllOnSubmit(col);
ItemDB.SubmitChanges();
this.IsDataLoaded = true;
// ???
}
}
public class VisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value != null && value is bool && parameter != null)
{
var bValue = (bool) value;
var visibility = (Visibility)Enum.Parse(
typeof (Visibility), parameter.ToString(),true);
if (bValue) return visibility;
return visibility ==
Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
Visibility="{Binding IsDownloading, Converter={StaticResource VisibilityConverter}, ConverterParameter=Visible}"
Dispatcher.BeginInvoke(delegate
{
NavigationService.Navigate(new Uri("/Folder/pagename.xaml", UriKind.Relative));
});