Skip to content

Clipboard issue#305

Open
mavaddat wants to merge 2 commits intow-ahmad:mainfrom
mavaddat:clipboard_issue
Open

Clipboard issue#305
mavaddat wants to merge 2 commits intow-ahmad:mainfrom
mavaddat:clipboard_issue

Conversation

@mavaddat
Copy link

Summary

This PR fixes an issue #304 where pressing Ctrl+C inside an editable TableViewTemplateColumn cell causes a WinRT clipboard exception (CLIPBRD_E_CANT_OPEN, HRESULT 0x800401D0) to escape the control and crash the application.


What this PR changes

1. Add exception handling around Clipboard.SetContent

(Commit: Handle clipboard exceptions)

Clipboard access can fail for normal, expected reasons. Wrapping the call in a try/catch prevents the application from crashing:

try
{
    Clipboard.SetContent(package);
}
catch (Exception ex)
{
    Debug.WriteLine($"TableView: Clipboard.SetContent failed: {ex}");
}

This matches the defensive clipboard handling used in WPF, WinForms, UWP, and other frameworks.


2. Skip TableView‑level copy when a cell editor already handles Ctrl+C

(Commit: Skip copy on simple text fields)

When a TextBox, PasswordBox, or RichEditBox is focused, these controls already implement their own copy behavior. In such cases, TableView should not attempt to perform its own copy:

var focused = FocusManager.GetFocusedElement() as FrameworkElement;
if (focused is TextBox || focused is PasswordBox || focused is RichEditBox)
{
    return;
}

This avoids duplicate clipboard operations and prevents the control from invoking its own copy logic unnecessarily.


Why this fix is correct

  • Prevents application crashes caused by normal clipboard contention
  • Preserves existing TableView copy behavior when appropriate
  • Avoids interfering with built‑in editor copy behavior
  • Keeps the fix localized and easy to maintain
  • Does not change public API surface
  • Matches defensive patterns used in other UI frameworks

Conclusion

This PR makes WinUI.TableView more robust by:

  • Preventing clipboard‑related crashes
  • Respecting cell editor copy behavior
  • Ensuring TableView copy logic only runs when appropriate

The changes are minimal, safe, and improve the reliability of the control in real‑world applications.

Thank you for maintaining this project — happy to adjust anything if needed.

@w-ahmad
Copy link
Owner

w-ahmad commented Feb 3, 2026

@mavaddat in my opinion should always skip copy operation on a template column. shouldn't we?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants