DataGrid列在打印时不调整大小

时间:2013-01-25 19:40:07

标签: wpf xaml datagrid datagridcolumn

我有一个应用程序从传感器获取数据,然后从该数据输出Graphs和Datagrid。

什么有用:   我正在使用usercontrol生成一个报告,该报告插入到一个fixedPage中,并在DocumentViewer的帮助下显示在FixedDocument中。

我做了什么:   为了促进许多事情,启用文本搜索,预生成报告,...,我决定将我的FixedDocument转换为XpsDocument并将其放入DocumentViewer。

我的问题:   出于某种原因,除了我的DataGrid列之外,转换的所有内容都没有改变。我正在手工插入Xaml中的列,每个都有1 *的宽度。但我得到的结果就好像它完全无视调整大小。它甚至没有适当地调整内容大小。

修正了什么:当我放置一个固定的宽度时,它会在查看器中得到尊重。

代码

var actualReport = new FixedDocument();
actualReport.DocumentPaginator.PageSize = new Size(8.5 * 96, 11 * 96);
actualReport.Pages.Add(new PageContent { Child = new FixedPage { Children = {
            new FrontPage { Width = 8.5 * 96, Height = 11 * 96, DataContext = d, }
        }
    }
});

[.. Three more pages ..]

var ms = new MemoryStream();
var pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);

string pack = "pack://temp.xps";
PackageStore.AddPackage(new Uri(pack), pkg);

var doc = new XpsDocument(pkg, CompressionOption.SuperFast, pack);
XpsSerializationManager rsm = 
    new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
rsm.SaveAsXaml(actualReport.DocumentPaginator);
Viewer.Document = doc.GetFixedDocumentSequence();

风格

<Style TargetType="DataGrid" x:Key="PrintGrid">
    <Setter Property="IsReadOnly" Value="True" />
    <Setter Property="BorderBrush" Value="{x:Null}" />
    <Setter Property="Background" Value="{x:Null}" />
    <Setter Property="AutoGenerateColumns" Value="False" />
    <Setter Property="CanUserSortColumns" Value="False" />
    <Setter Property="CanUserResizeColumns" Value="False" />
    <Setter Property="CanUserResizeRows" Value="False" />
    <Setter Property="CanUserReorderColumns" Value="False" />
    <Setter Property="HeadersVisibility" Value="Column" />
    <Setter Property="FontSize" Value="16" />
</Style>

Xaml

<DataGrid Grid.Row="1" ItemsSource="{Binding CollectCtx.Sensors}" 
          Style="{DynamicResource PrintGrid}" HorizontalAlignment="Stretch">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Pos" Width="1*" Binding="{Binding Position}" />
        <DataGridTextColumn Header="Min" Width="1*"Binding="{Binding Data.Min, StringFormat={x:Static r:Resources.FormatTemp}}" />
        <DataGridTextColumn Header="Ave" Width="1*"  Binding="{Binding Data.Ave, StringFormat={x:Static r:Resources.FormatTemp}}" />
        <DataGridTextColumn Header="Max" Width="1*"  Binding="{Binding Data.Max, StringFormat={x:Static r:Resources.FormatTemp}}" />
        <DataGridTextColumn Header="Stab" Width="1*" Binding="{Binding Data.Stab, StringFormat={x:Static r:Resources.FormatTemp}}" />
        <DataGridTextColumn Header="Diff" Width="1*" >
            <DataGridTextColumn.Binding>
                <MultiBinding StringFormat="{x:Static r:Resources.FormatTemp}" Converter="{StaticResource DiffConverter}">
                    <Binding Path="Data.Ave" />
                    <Binding 
                            RelativeSource="{RelativeSource AncestorType={x:Type UserControl}}"
                            Path="DataContext.CollectCtx.Temperature" />
                </MultiBinding>
            </DataGridTextColumn.Binding>
        </DataGridTextColumn>
        <DataGridTextColumn  Header="Compliant" Width="1*" Binding="{Binding DataContext.CollectCtx, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource CompliantConverter}, Mode=OneWay}" />
    </DataGrid.Columns>
</DataGrid>

0 个答案:

没有答案