Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF DataGrid HTML clipboard data faulty #10476

Open
kniessen opened this issue Feb 19, 2025 · 2 comments · May be fixed by #10477
Open

WPF DataGrid HTML clipboard data faulty #10476

kniessen opened this issue Feb 19, 2025 · 2 comments · May be fixed by #10477
Labels
Bug Product bug (most likely) 🚧 work in progress Investigate Requires further investigation by the WPF team.

Comments

@kniessen
Copy link

Description

The HTML fragment DataGrid puts into the clipboard is not accepted by other applications.

It appears that the fragment's offsets (StartHTML/EndHTML/StartFragment/EndFragment) do not match the content.

Reproduction Steps

Select all data in a DataGrid, copy and then paste to Excel.

Expected behavior

Excel (or other application) correctly accepts HTML data from DatGrid in clipboard.

Actual behavior

Application cannot interpret and paste HTML data copied from DataGrid but display error.

Regression?

Error was introduced with #8519.

Known Workarounds

  1. Derive DataGrid subclass and override OnExecutedCopy:
        protected override void OnExecutedCopy(ExecutedRoutedEventArgs args)
        {
            base.OnExecutedCopy(args);

            String htmlData = Clipboard.GetData(DataFormats.Html) as String;
            htmlData = htmlData.Replace("\r\n\r\n", "\r\n");
            Clipboard.SetData(DataFormats.Html, htmlData);
        }

2. Manually select csv or other format when pasting data copied from DataGrid in other applications.

### Impact

High impact at my company's backoffice which uses copy/paste to Excel intensely. On a more general scale, probably low.

### Configuration

.Net 9 Win11

### Other information

The problem with the wrong offsets is a result of double CR/LFs between the header items in Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridClipboardHelper.cs (lines 86-102) - remove those and everything works as before.
@lindexi
Copy link
Member

lindexi commented Feb 19, 2025

Cc @halgab

The origin code: https://github.com/dotnet/wpf/pull/8519/files#diff-1e969bd11b05c363a95985d0554e02082433d0d7a563a91c72392b6fe23a6d9cL18

The code in #8519 : https://github.com/dotnet/wpf/pull/8519/files#diff-1e969bd11b05c363a95985d0554e02082433d0d7a563a91c72392b6fe23a6d9cR87-R116


@kniessen I try fix this issues in #10477 .

@lindexi lindexi added the Investigate Requires further investigation by the WPF team. label Feb 19, 2025
@lindexi lindexi linked a pull request Feb 19, 2025 that will close this issue
@halgab
Copy link
Contributor

halgab commented Feb 25, 2025

So sorry for the bug. I thought I had fixed manually this automatic addition of 2 new lines instead if one everywhere but I guess this one slipped through...

@h3xds1nz h3xds1nz added Bug Product bug (most likely) and removed 🪲 bug labels Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely) 🚧 work in progress Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants