Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am trying to copy a Datagrid to Clipboard and paste it into word or excel. The DataGridTextColumns are working well. But I need to copy an Image Column.

C#
             <DataGridTemplateColumn Header="Image"  Width="1"  IsReadOnly="True">
                   <DataGridTemplateColumn.CellTemplate>
                       <DataTemplate>
                           <Image  RenderOptions.BitmapScalingMode="NearestNeighbor"
                           RenderOptions.EdgeMode="Aliased" Stretch="UniformToFill" Source="{Binding ImagePf}" />
                       </DataTemplate>
                   </DataGridTemplateColumn.CellTemplate>

                   <DataGridTemplateColumn.ClipboardContentBinding>
                   <Binding Path="ImagePf" />
               </DataGridTemplateColumn.ClipboardContentBinding>
</DataGridTemplateColumn>


It copies only the path to the Image and not the Image itselfs.


C#
<DataGridTextColumn  Header="Level"  IsReadOnly="True"    >
    <!-- Binding="{Binding Level,Converter={StaticResource LogLevelStringConverter}}"-->
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell" >
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DataGridCell">
                        <Grid  >
                            <ContentPresenter VerticalAlignment="Center" Margin="20,0,0,0" HorizontalAlignment="Left"  />
                            <Image Grid.Column="0" RenderOptions.BitmapScalingMode="NearestNeighbor"
                            RenderOptions.EdgeMode="Aliased" Stretch="UniformToFill" Source="{Binding ImagePf}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

I also tried to use the DataGridTextColumn but it does not copy the Image.

What I have tried:

I have tried to use the ClipboardContentBinding for the DataGridTemplateColumn and I tried to use the TextColumn instead of the TemplateColumn but both does work.

I was not able to find a possible solution to implement it.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900