async void deleteButton_Click(object sender, EventArgs e) { Dispatcher.BeginInvoke(() => { TypingIndicator.IsVisible = true; titleBar.Text = AppResources.DeletingText.ToUpper(); imagesList.IsEnabled = false; }); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, String.Format("https://api.imgur.com/3/image/{0}", selectedImage.DeleteHash)); request.Headers.Add("Authorization", "Client-ID " + AppResources.ImgurApiKey); HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); try { //make request Task <HttpResponseMessage> resultTask = new HttpClient().SendAsync(request); result = await resultTask; } catch { Dispatcher.BeginInvoke(() => { TypingIndicator.IsVisible = false; titleBar.Text = AppResources.ApplicationTitle.ToUpper(); MessageBox.Show(AppResources.ImageDeleteErrorText); imagesList.IsEnabled = true; }); return; } Debug.WriteLine("Response: {0}", result.Content.ReadAsStringAsync().Result); if (result.Content.ReadAsStringAsync().Result.IndexOf("200") < 0) { Dispatcher.BeginInvoke(() => { TypingIndicator.IsVisible = false; titleBar.Text = AppResources.ApplicationTitle.ToUpper(); MessageBox.Show(AppResources.ImageDeleteErrorText); imagesList.IsEnabled = true; }); return; } Dispatcher.BeginInvoke(() => { TypingIndicator.IsVisible = false; titleBar.Text = AppResources.ApplicationTitle.ToUpper(); imagesList.IsEnabled = true; images.Remove(selectedImage); imagesList.SelectedItem = null; selectedImage = null; appSettings["images"] = images; appSettings.Save(); ApplicationBar.Mode = ApplicationBarMode.Minimized; ApplicationBar.Buttons.Clear(); }); }
private void imagesList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (imagesList.SelectedItem == null) { return; } selectedImage = null; ApplicationBar.Mode = ApplicationBarMode.Minimized; ApplicationBar.Buttons.Clear(); this.selectedImage = (ImgurImage)(imagesList.SelectedItem); ApplicationBar.Buttons.Add(copyButton); ApplicationBar.Buttons.Add(openButton); ApplicationBar.Buttons.Add(deleteButton); ApplicationBar.Mode = ApplicationBarMode.Default; imagesList.SelectedItem = null; }