protected async override Task ActionHandler(Object sender, DependencyObject source, bool enqueue) { try { var dg = VisualTreeUtils.FindAncestor <DataGrid>((DataGridRow)sender); await this.playbackService.EnqueueAsync(dg.Items.OfType <TrackViewModel>().ToList(), (TrackViewModel)dg.SelectedItem); } catch (Exception ex) { Tracer.Error("Error while handling DataGrid action. Exception: {0}", ex.Message); } }
protected async Task DataGridActionHandler(object sender) { try { var dg = VisualTreeUtils.FindAncestor <DataGrid>((DataGridRow)sender); await this.playBackService.Enqueue(dg.Items.OfType <TrackInfoViewModel>().ToList().Select(tivm => tivm.TrackInfo).ToList(), ((TrackInfoViewModel)dg.SelectedItem).TrackInfo); } catch (Exception ex) { LogClient.Instance.Logger.Error("Error while handling DataGrid action. Exception: {0}", ex.Message); } }
private void ListboxNotes_DoubleClick(object sender, MouseButtonEventArgs e) { // This code checks if the source of the double-click was a ListBoxItem // If not, we don't open the currently selected note ListBoxItem listBoxItem = VisualTreeUtils.FindAncestor <ListBoxItem>((DependencyObject)e.OriginalSource); if (listBoxItem == null) { return; } if (e.ChangedButton == MouseButton.Left) { this.eventAggregator.GetEvent <OpenNoteEvent>().Publish(""); } }
private async void DataGridTracks_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { // Prevent DataGrid.KeyDown to make the selection to go to the next row when pressing Enter e.Handled = true; // Makes sure that this action is triggered by a DataGridCell. This prevents // enqueuing when clicking other ListBox elements (e.g. the ScrollBar) DataGridCell dataGridCell = VisualTreeUtils.FindAncestor <DataGridCell>((DependencyObject)e.OriginalSource); if (dataGridCell == null) { return; } DataGrid dg = (DataGrid)sender; await this.playbackService.EnqueueAsync(dg.Items.OfType <TrackViewModel>().ToList(), (TrackViewModel)dg.SelectedItem); } }