Enable DataGrid Copy with Custom Columns

柔情痞子 提交于 2020-01-15 07:26:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!