选中datagrid后,对选中的数据进行复制粘贴:
复制是显示在datagrid的右键弹出,粘贴通过按钮实现:
1.复制:
<dg:DataGrid x:Name="dg" ItemsSource="{Binding}" Margin="10"
Background="#80909090" AlternationCount="2">
<dg:DataGrid.ContextMenu >
<ContextMenu >
<MenuItem Header="Copy Selected Transactions"
Command="{x:Static ApplicationCommands.Copy}" />
</ContextMenu>
</dg:DataGrid.ContextMenu>
<!-- <ListView.View> ...
</ListView.View> -->
</dg:DataGrid>
只用到command的命令即可;
2.粘贴按钮如下:
private StringBuilder PasteRockData()
{
StringBuilder sb = new StringBuilder();
IDataObject ido = Clipboard.GetDataObject();
if (ido != null)
{
string[] formats = ido.GetFormats();
string format = formats[0].ToString();
object data = ido.GetData(format);
sb.Append(data);
}
return sb;
}
通过字符串流的形式进行读取