public T GetCommandFromCommandButtons <T>(object sender) where T : CommandBase { CommandButtonsControl commandButtonsControl = (CommandButtonsControl)sender; if (commandButtonsControl.DataContext != null && commandButtonsControl.DataContext is CommandBase) { return((T)commandButtonsControl.DataContext); } return(null); }
private async void PlayButton_Click(object sender, RoutedEventArgs e) { this.PlayButton.Visibility = Visibility.Collapsed; this.StopButton.Visibility = Visibility.Visible; this.newCommand = await this.GetNewCommand(); if (this.newCommand != null) { await CommandButtonsControl.TestCommand(this.newCommand); } this.SwitchToPlay(); }
private async void PlayButton_Click(object sender, RoutedEventArgs e) { this.PlayButton.Visibility = Visibility.Collapsed; this.StopButton.Visibility = Visibility.Visible; this.EditButton.IsEnabled = false; this.DeleteButton.IsEnabled = false; this.EnableDisableToggleSwitch.IsEnabled = false; CommandBase command = this.GetCommandFromCommandButtons <CommandBase>(this); await CommandButtonsControl.TestCommand(command); this.SwitchToPlay(); this.RaiseEvent(new RoutedEventArgs(CommandButtonsControl.PlayClickedEvent, this)); }
public T GetCommandFromCommandButtons <T>(object sender) where T : CommandBase { CommandButtonsControl commandButtonsControl = (CommandButtonsControl)sender; if (commandButtonsControl.DataContext != null) { if (commandButtonsControl.DataContext is CommandBase) { return((T)commandButtonsControl.DataContext); } else if (commandButtonsControl.DataContext is EventCommandItem) { EventCommandItem commandItem = (EventCommandItem)commandButtonsControl.DataContext; return((T)((CommandBase)commandItem.Command)); } } return(null); }