I've recently upgraded my WP7 app to Mango and am having some problems with the camera. The code below used to work on 7.0, but on 7.1 the completed handler fires before the dialog is even shown, so I can't capture the result. After taking the photo, the phone displays "Resuming..." which it never used to do.
var dlg = new CameraCaptureTask();
dlg.Completed += (s, e) =>
{
if (e.TaskResult == TaskResult.OK) {
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
//var img = new Image();
//img.Source = bmp;
string caption = string.Empty;
var inputDialog = new InputPrompt()
{
Title = "Caption",
Message = "Enter caption/description for snapshot",
};
inputDialog.Completed += (ss, ee) =>
{
if (ee.PopUpResult == PopUpResult.Ok)
{
caption = ee.Result;
var snap = SnapshotBLL.AddSnapshot(recipeId, bmp, caption);
onComplete(null, new SnapshotEventArgs(snap));
}
};
inputDialog.Show();
}
};
dlg.Show();
The MSDN docs appear to show a variation of my code but I can no longer get the result of the camera capture task.
Assuming that your sample comes from a single method I wouldn't expect it to ahve worked pre Mango.
The CameraCaptureTask
should be created and the callback assigned in the constructor of the page for it to work properly.
Something like:
public partial class MainPage : PhoneApplicationPage
{
private CameraCaptureTask cct = new CameraCaptureTask();
public MainPage()
{
InitializeComponent();
cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
}
private void cct_Completed(object sender, PhotoResult e)
{
// Do whatever here
}
private void SomeEventHandler(object sender, RoutedEventArgs e)
{
cct.Show();
}
}
This works in both 7.0 & 7.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With