private void Copy_Device_Click(object sender, RoutedEventArgs e) { if (sender is Button devBtn && devBtn.DataContext is ComputeDevice sourceDevice) { _deviceData.CopySettingsFromAnotherDevice(sourceDevice); if (this.TemplatedParent is ContextMenu parentContext) { parentContext.IsOpen = false; } } }