问题
I have a DataGrid where I have Custom Columns with Column Templates to insert special Tooltips. When doing that, how do I enable copying this data to clipboard?
XAML-Code of my DataGrid:
<DataGrid x:Name="CapabilityGrid" IsReadOnly="True" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Variable">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" ToolTip="{Binding Name, Converter={StaticResource tooltipConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Value">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
回答1:
You can use ClipboardContentBinding
Gets or sets the binding object to use when getting or setting cell content for the clipboard.
so in XAML you can do
<DataGridTemplateColumn Header="Value" ClipboardContentBinding="{Binding Value}">
来源:https://stackoverflow.com/questions/24161543/enable-datagrid-copy-with-custom-columns