dotnet / dotnet/wpf

DataGrid: apply binding StringFormat when copying to the clipboard

Open
#5,385 2 comments 5 reactions 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

Currently, if you define a StringFormat value in a binding for a column, it faithfully reproduces the format for the displayed value, but ignores the format when copying to the clipboard.

Simple example:
```xml

```
A value of `.1234` will display as `12.34%` but copy as `.1234`.

This also applies when using a ClipboardContentBinding:
```xml

```

Here, a value of `2.50` will display as `$2.50` and copy as `2.50` rather than `$2.5000` as one might expect.

Passing a pre-formatted string to the column fixes the clipboard behavior, but it can come at the cost of proper sorting (e.g., date values and most non-ISO-8601 date formats).

To properly format the clipboard value without this trade-off involves passing a pre-formatted or value-converted value to ClipboardContentBinding, e.g.:
```xml

```

_minimal example project attached_
[testclipboardformatting.zip](https://github.com/dotnet/wpf/files/7227395/testclipboardformatting.zip)

---

A much preferable behavior would be to utilize the StringFormat from the ClipboardContentBinding (or Binding) automatically so such work-arounds aren't required.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.