private async void btn_AgregarImagen_Tapped(object sender, TappedRoutedEventArgs e) { profesor_seleccionado = null; FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); var image = new BitmapImage(); image.SetSource(stream); Stream imgStream = stream.AsStream(); imgStream.Position = 0; if (profesor_seleccionado != null) { profesor_seleccionado.profesor.imagen = imgStream; } imgPtr = imgStream; img_profesor.Source = image; } }
private async void ProfesoresGrid_ItemClick(object sender, ItemClickEventArgs e) { ProfesoresItem item = (e.ClickedItem) as ProfesoresItem; profesor_seleccionado = item; MemoryStream stream = null; BitmapImage bitmap = null; if (item.Categoria == "Agregar") { btn_Agregar.IsEnabled = true; btn_Agregar.Visibility = Visibility.Visible; btn_Actualizar.IsEnabled = false; btn_Actualizar.Visibility = Visibility.Collapsed; btn_Eliminar.IsEnabled = false; btn_Eliminar.Visibility = Visibility.Collapsed; } else { btn_Agregar.IsEnabled = false; btn_Agregar.Visibility = Visibility.Collapsed; btn_Actualizar.IsEnabled = true; btn_Actualizar.Visibility = Visibility.Visible; btn_Eliminar.IsEnabled = true; btn_Eliminar.Visibility = Visibility.Visible; txtbx_Nombre.Text = item.profesor.nombre; txtbx_Apellidos.Text = item.profesor.apellidos; txtbx_Departamento.Text = item.profesor.departamento; txtbx_codigo_postal.Text = item.profesor.cod_postal.ToString(); txtbx_provincia.Text = item.profesor.provincia; txtbx_correo.Text = item.profesor.correo; try { if (item.profesor.imagen != null) { stream = new MemoryStream(); await item.profesor.imagen.CopyToAsync(stream); bitmap = new BitmapImage(); item.profesor.imagen.Position = 0; stream.Position = 0; await bitmap.SetSourceAsync(stream.AsRandomAccessStream()); await item.profesor.imagen.FlushAsync(); await stream.FlushAsync(); img_profesor.Source = bitmap; } } catch (Exception eSql) { await new Windows.UI.Popups.MessageDialog("Error al leer la imagen!").ShowAsync(); System.Diagnostics.Debug.WriteLine("Error!: " + eSql.Message); } } AgregarProfesoresPopup.IsOpen = true; }