|
8 | 8 | using System.Collections.Generic; |
9 | 9 | using System.ComponentModel; |
10 | 10 | using System.ComponentModel.DataAnnotations; |
| 11 | +using System.Diagnostics; |
11 | 12 | using System.IO; |
12 | 13 | using System.Linq; |
13 | 14 | using System.Reflection; |
@@ -447,17 +448,44 @@ private TableViewCellSlot GetNextSlot(TableViewCellSlot? currentSlot, bool isShi |
447 | 448 | /// </summary> |
448 | 449 | internal void CopyToClipboardInternal(bool includeHeaders) |
449 | 450 | { |
| 451 | + // Skip TableView copy logic when a cell editor already handles Ctrl+C. |
| 452 | + // TextBox, PasswordBox, and RichEditBox all implement their own copy behavior. |
| 453 | + var focused = FocusManager.GetFocusedElement() as FrameworkElement; |
| 454 | + if (focused is TextBox || focused is PasswordBox || focused is RichEditBox) |
| 455 | + { |
| 456 | + return; |
| 457 | + } |
| 458 | + |
450 | 459 | var args = new TableViewCopyToClipboardEventArgs(includeHeaders); |
451 | 460 | OnCopyToClipboard(args); |
452 | 461 |
|
453 | 462 | if (args.Handled) |
454 | 463 | { |
455 | 464 | return; |
456 | 465 | } |
| 466 | + |
| 467 | + var content = GetSelectedClipboardContent(includeHeaders); |
457 | 468 |
|
458 | | - var package = new DataPackage(); |
459 | | - package.SetText(GetSelectedClipboardContent(includeHeaders)); |
460 | | - Clipboard.SetContent(package); |
| 469 | + if (string.IsNullOrWhiteSpace(content)) |
| 470 | + { |
| 471 | + return; |
| 472 | + } |
| 473 | + |
| 474 | + // Try/catch to prevent CLIPBRD_E_CANT_OPEN crashes. |
| 475 | + try |
| 476 | + { |
| 477 | + var package = new DataPackage(); |
| 478 | + package.SetText(content); |
| 479 | + |
| 480 | + Clipboard.SetContent(package); |
| 481 | + } |
| 482 | + catch (Exception ex) |
| 483 | + { |
| 484 | + // Clipboard failures are normal on Windows (e.g., CLIPBRD_E_CANT_OPEN). |
| 485 | + // Swallow to avoid crashing the application. |
| 486 | + Debug.WriteLine( |
| 487 | + $"TableView: Clipboard.SetContent failed: {ex}"); |
| 488 | + } |
461 | 489 | } |
462 | 490 |
|
463 | 491 | /// <summary> |
|
0 commit comments