Wpf datagrid copy and paste what you see

I use a data grid in wpf and it copies and pastes by default.

I have a date time column, and I used the binding and string format to show it in the date format I want.

However, when I copy and paste, the pasted text becomes an unformatted date time.

Is there a way to make a copy of the paste on "What do you see, what do you get?"

Thanks Kev

Edit: I tried using ClipboardContentBinding, adding the same as in the binding. And it didn’t work

+6
source share
1 answer

There are several clipboard extensibility points in the DataGrid with which you can connect and see what happens. The grid itself has a CopyingRowClipboardContent event, which, in addition to having all the necessary information in the event arguments, has a nice helper method, FormatClipboardCellValues ​​(string format) . In addition, each column has a CopyingCellClipboardContent that can be used for your specific data column needs.

Note. By default, bound DataGrid columns (those obtained from a DataGridBoundColumn ) will have their ClipboardContentBinding pointing to the Binding property, unless explicitly specified.

+1
source

Source: https://habr.com/ru/post/894210/


All Articles