With Silverlight 4, I can select one or more cells (or rows and columns) in a DataGrid, hit Control+C and the contents are copied to the clipboard. Which is really cool. Upon Control+V, it can be pasted into Excel or some other editor.
However, the if one of the columns is a DataGridTemplateColumn it's values are blank when pasted. Which makes sense, because it could be anything in the column.
How can I tell the Control+C copy what the value of the template cell should be?
Turns out this is really easy if you are using data binding. All you have to do is bind the
ClipboardContentBindingproperty with the value you want copied for this column.
For example:
<data:DataGridTemplateColumn Header="Name" ClipboardContentBinding="{Binding Name}" SortMemberPath="Name">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton Content="{Binding Name}" Margin="3" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With