我有以下带有自定义视觉效果的DataGrid:
是否可以将此DataGrid导出为pdf文件,以保留所有自定义视觉效果?
如果它帮助某人在这里是我的datagrid的xaml(代码是混乱的,可能不是最佳的,但这不是现在的重点,我只是需要帮助pdf的问题),也是另一个注意,我从C#添加列:
<DataGrid Name="dgMain" AlternationCount="2" AlternatingRowBackground="#f2f2f2" IsReadOnly="True" GridLinesVisibility="None" VerticalGridLinesBrush="White">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="LightGray"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border BorderThickness="1" Padding="3,0,3,0" Height="{TemplateBinding Height}" Grid.Column="0">
<Border.Background>
<SolidColorBrush Color="#c7d9f1"/>
</Border.Background>
<ContentPresenter VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
</Border>
<Thumb x:Name="PART_RightHeaderGripper" Grid.Column="1" HorizontalAlignment="Right" Width="2" BorderThickness="1" Cursor="SizeWE" BorderBrush="{Binding VerticalGridLinesBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Padding" Value="10" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Padding="{TemplateBinding Padding}">
<ContentPresenter></ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
</DataGrid.Columns>
</DataGrid>
2条答案
按热度按时间6ioyuze21#
我已经修改了这个example,以适应数据网格中的动态列计数,这建议安装iTextSharp nuget包。
https://www.nuget.org/packages/itext7/
sd2nnvve2#
下面是一个使用iText 7的例子,类似于@farrukh-niaz的回答。