private async void BtnAddId_Click(object sender, RoutedEventArgs e) { string videoId = tbxNewId.Text; if (Model.Videos.Any(video => video.ID == videoId)) { MessageBox.Show("Video already in list", "Error", MessageBoxButton.OK, MessageBoxImage.Information); return; } FrameworkElement element = (FrameworkElement)sender; element.IsEnabled = false; YouTubeVideo video = new YouTubeVideo() { ID = tbxNewId.Text }; try { await video.LoadOEmbedData(); int index = Model.Videos.TakeWhile(v => v.OEmbed.title.CompareTo(video.OEmbed.title) < 0).Count(); Model.Videos.Insert(index, video); tbxNewId.Text = ""; } catch (Exception exc) { MessageBox.Show(exc.Message, "Loading data error", MessageBoxButton.OK, MessageBoxImage.Error); } element.IsEnabled = true; }
private async void BtnReloadOEmbed_Click(object sender, RoutedEventArgs e) { FrameworkElement element = (FrameworkElement)sender; element.IsEnabled = false; YouTubeVideo video = (YouTubeVideo)element.DataContext; try { await video.LoadOEmbedData(); } catch (Exception exc) { MessageBox.Show(exc.Message, "Loading data error", MessageBoxButton.OK, MessageBoxImage.Error); } element.IsEnabled = true; }