Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy the selected contents of all cells in a DataGrid (including DataGridTemplateColumn) with Silverlight 4?

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?

like image 953
Ben Farmer Avatar asked Aug 13 '10 14:08

Ben Farmer


1 Answers

Turns out this is really easy if you are using data binding. All you have to do is bind the

ClipboardContentBinding
property 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>
like image 119
Ben Farmer Avatar answered Sep 19 '22 15:09

Ben Farmer