-
-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Summary
Pressing Ctrl+C inside an editable TableViewTemplateColumn cell causes a WinRT clipboard exception to escape the control and crash the application. The exception is thrown from Clipboard.SetContent inside TableView.CopyToClipboardInternal, and it is not caught by the control.
This issue occurs only inside WinUI.TableView.
Copying from TextBox, RichEditBox, or any other WinUI 3 control does not reproduce the crash.
The exception does not reach Application.UnhandledException, because it is intercepted by the auto‑generated XAML handler in App.g.i.cs, causing the debugger to break immediately.
This makes the crash unavoidable unless the app manually intercepts Ctrl+C inside the cell editor.
Affected Version
WinUI.TableView 1.3.4
Windows App SDK 1.6.250108002
.NET 8.0
Windows 10.0.19041
Reproduction Steps
- Create a WinUI 3 app.
- Add a
TableViewwith aTableViewTemplateColumncontaining aTextBox(editable cell). - Run the app.
- Click inside the editable cell to focus the
TextBox. - Press Ctrl+C.
Actual Behavior
The application crashes with an unhandled WinRT clipboard exception:
HResult: -2147221040 (0x800401D0)
CLIPBRD_E_CANT_OPEN
Stack trace:
WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
ABI.Windows.ApplicationModel.DataTransfer.IClipboardStaticsMethods.SetContent(...)
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(DataPackage content)
WinUI.TableView.TableView.CopyToClipboardInternal(Boolean includeHeaders)
WinUI.TableView.TableView.HandleShortKeys(Boolean shiftKey, Boolean ctrlKey, VirtualKey key)
WinUI.TableView.TableView.OnKeyDown(KeyRoutedEventArgs e)
ABI.Microsoft.UI.Xaml.Controls.IControlOverrides.Do_Abi_OnKeyDown_18(...)
The exception is not handled by the control and does not reach Application.UnhandledException.
Expected Behavior
- Pressing Ctrl+C inside an editable cell should either:
- Copy the selected text normally (preferred), or
- Do nothing, or
- Fail silently
It should not crash the application.
Clipboard access is known to fail intermittently on Windows (e.g., when another process temporarily locks the clipboard). Controls that call Clipboard.SetContent should wrap it in a try/catch.
Minimal Reproducible Example
MainWindow.xaml
<Window
x:Class="TableViewCrashTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tv="using:WinUI.TableView">
<Grid>
<tv:TableView x:Name="MyTable"
AutoGenerateColumns="False">
<tv:TableView.Columns>
<tv:TableViewTemplateColumn Header="Editable">
<tv:TableViewTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Value, Mode=TwoWay}"
BorderThickness="0"
Padding="4" />
</DataTemplate>
</tv:TableViewTemplateColumn.CellTemplate>
</tv:TableViewTemplateColumn>
</tv:TableView.Columns>
</tv:TableView>
</Grid>
</Window>MainWindow.xaml.cs
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MyTable.ItemsSource = new[]
{
new TestRow { Value = "Try Ctrl+C here" }
};
}
}
public class TestRow
{
public string Value { get; set; }
}Repro Instructions
- Run the app.
- Click inside the
TextBoxcell. - Press Ctrl+C.
- Application crashes with
CLIPBRD_E_CANT_OPEN.
Additional Notes
- The issue only occurs inside
WinUI.TableView. - Copying from:
TextBoxRichEditBox- Any other WinUI 3 control
does not reproduce the crash.
- The exception originates inside
TableView.CopyToClipboardInternal. - The control does not wrap clipboard access in a
try/catch. - Because the exception is thrown inside WinRT interop, it bypasses
Application.UnhandledExceptionand triggers the auto‑generated XAML break handler.
Workaround
Intercept Ctrl+C inside the cell editor:
private void CellEditor_KeyDown(object sender, KeyRoutedEventArgs e)
{
var ctrl = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control)
.HasFlag(CoreVirtualKeyStates.Down);
if (ctrl && e.Key == VirtualKey.C)
e.Handled = true;
}This prevents the crash but potentially disables copy functionality inside the TableView (it seems that copy still works even with this intercept).
Request
Please update TableView.CopyToClipboardInternal to:
- Wrap
Clipboard.SetContentin atry/catch - Avoid propagating WinRT clipboard exceptions
- Optionally check clipboard availability before calling
SetContent
This will prevent application crashes and align the control with expected WinUI behavior.