I have this code and I use it to show a button that allows the user to select an image from his library and use it as a background for my application.
So, I create PhotoChooserTask , set it to show the camera and bind it to the method that should be executed when the task is completed. The button will launch the task, showing PhotoChooserTask . The completion action is pretty simple, I just have to set a boolean and update the image source.
PhotoChooserTask pct_edit = new PhotoChooserTask(); pct_edit.ShowCamera = true; pct_edit.Completed += pct_edit_Completed; Button changeImageButton = new Button { Content = "Change Image" }; changeImageButton.Tap += (s, e) => { pct_edit.Show(); }; void pct_edit_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { bi.SetSource(e.ChosenPhoto); IsRebuildNeeded = true; } }
The problem is that it will not show PhotoChooserTask , but that will give me an exception, forcing me to
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) { Debugger.Break(); } }
in App.xaml.cs
This looks weird as I have another PhotoChooserTask in the same class and this file works fine.
What is wrong with him?
VisualStudio won't even tell me what an exception is, and therefore there is no way to figure it out!
EDIT:
I just found out that an exception is thrown when I call
pct_edit.Show();
in the button click event.
source share