XAMDataGrid 末尾的标签



我有一个XAMDataGrid,用于通过以下代码填充报告。

其中 EGMList 是模型。在此处输入图像描述

报告.Xaml

 <dataPresenter:XamDataGrid x:Name="datagdStatus" DataSource="{Binding EgmList}" DockPanel.Dock="Top"
                          HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch"  GroupByAreaLocation="None" FontFamily="Arial" FontSize="11" Visibility="Hidden">
                    <dataPresenter:XamDataGrid.FieldLayoutSettings>
                        <dataPresenter:FieldLayoutSettings RecordSelectorLocation="None" AllowAddNew="False" AllowDelete="False"  AutoGenerateFields="False" />
                    </dataPresenter:XamDataGrid.FieldLayoutSettings>
                    <dataPresenter:XamDataGrid.FieldLayouts >
                        <dataPresenter:FieldLayout >
                            <dataPresenter:FieldLayout.Fields>
                                <dataPresenter:Field Name="Id" Label="{x:Static p:resource.tab_report_machineid}" Width="1.8*" Visibility="Collapsed">
                                    <dataPresenter:Field.Settings>
                                        <dataPresenter:FieldSettings AllowEdit="False" LabelTextAlignment="Center" EditorStyle="{StaticResource TextEditor}" LabelTextWrapping="Wrap"  />
                                    </dataPresenter:Field.Settings>
                                </dataPresenter:Field>
                                <dataPresenter:Field Name="MacAddress" Label= "{x:Static p:resource.UID}" Width="4*">
                                    <dataPresenter:Field.Settings>
                                        <dataPresenter:FieldSettings AllowEdit="False" LabelTextAlignment="Left" LabelTextWrapping="Wrap" />
                                    </dataPresenter:Field.Settings>
                                </dataPresenter:Field>
                                <dataPresenter:Field Name="HouseNumber" Label= "{x:Static p:resource.tab_chn_houseNumber_Title}" Width="3.3*" >
                                    <dataPresenter:Field.Settings>
                                        <dataPresenter:FieldSettings AllowEdit="False" LabelTextAlignment="Left" />
                                    </dataPresenter:Field.Settings>
                                </dataPresenter:Field>
                                <dataPresenter:Field Name="Type" Label="{x:Static p:resource.tab_report_type}" Width="2.5*" >
                                    <dataPresenter:Field.Settings>
                                        <dataPresenter:FieldSettings AllowEdit="False" LabelTextAlignment="Left" LabelTextWrapping="Wrap" />
                                    </dataPresenter:Field.Settings>
                                </dataPresenter:Field>
                                <dataPresenter:Field Name="Status" Label="{x:Static p:resource.tab_redeem_status}" Width="5*" >
                                    <dataPresenter:Field.Settings>
                                        <dataPresenter:FieldSettings AllowEdit="False" LabelTextAlignment="Left" />
                                    </dataPresenter:Field.Settings>
                                </dataPresenter:Field>
                           </dataPresenter:FieldLayout.Fields>
                        </dataPresenter:FieldLayout>
                    </dataPresenter:XamDataGrid.FieldLayouts>
                </dataPresenter:XamDataGrid>
            </DockPanel>

报告.Xaml.cs

  private void btnAllStatusPrint_Click(object sender, RoutedEventArgs e)
    {
        if (RedeemVoucherViewModel.EgmList.Count != 0)
        {
            Report reportObj = new Report();
            // set scale mode
            reportObj.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Scale;
            reportObj.PageHeaderTemplate = this.Resources["PagePresenterHeaderTemplate_small"] as DataTemplate;
            //  reportObj.PageContentTemplate = this.TryFindResource("basicContentTemplate") as DataTemplate;
            string siteControllerName = RedeemVoucherView.getSiteControllerName();
           // reportObj.PageFooter = "Total Machines :23";
            reportObj.PageHeader = string.Format("{0} {2} {1}", siteControllerName, DateTime.Now.ToString("dd/MM/yyyy"), Environment.NewLine);
            reportObj.ReportSettings.PageSize = new Size(3.13, 6);
            // create section and add it to report's section collection
            reportObj.ReportSettings.Margin = new Thickness(0, 0, 0, 0);
            EmbeddedVisualReportSection section = new EmbeddedVisualReportSection(datagdStatus);
            reportObj.Sections.Add(section);
            reportObj.Print(true, false);
            rteventLogger.WriteLog(TraceEventType.Information, "All Status report is printed", WMSTrace.ScopeTypes.Internal);
        }
        else
        {
            MessageBoxHelper.Show("No content available to print", MessageBoxImage.Information);
        }
    }
报表

在上述函数调用中打印,并在报表网格中填充 EGMList 的内容。

我想在报告末尾有一个摘要标签,其中包含记录/临时股东大会的计数

尝试将其添加到页面页脚中,但没有运气,因为它在所有页面中打印。

还尝试从代码隐藏中添加不同的部分,但这也显示了一起占用不同的页面。

请对此提出任何建议?

不幸的是,

这不是一件容易的事情。

首先,我认为我只需要为Report定义一个新FooterTemplate,并根据页脚是否在最后一页上隐藏或显示页脚。

不幸的是,报告生成的方式是您不知道总共将生成多少页,因此在数据模板中,您不知道是否正在模板化最后一页。

来源

:来源1

源 2

:源 2

解决方法

我只能为您提供解决方法。如果您不介意生成两次报告,这是可行的。首先,我们生成它,以便获得总页数,我们可以使用它设置FooterTemplate

private void btnAllStatusPrint_Click(object sender, RoutedEventArgs e)
{
    if (RedeemVoucherViewModel.EgmList.Count != 0)
    {
        Report reportObj = new Report();
        // set scale mode
        reportObj.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Scale;
        reportObj.PageHeaderTemplate = this.Resources["PagePresenterHeaderTemplate_small"] as DataTemplate;
        string siteControllerName = RedeemVoucherView.getSiteControllerName();
        reportObj.PageFooter = string.Format("Total Machines: {0}", MyXamDataGrid.DataItems.Count);
        reportObj.PageHeader = string.Format("{0} {2} {1}", siteControllerName, DateTime.Now.ToString("dd/MM/yyyy"), Environment.NewLine);
        reportObj.ReportSettings.PageSize = new Size(3.13, 6);
        // create section and add it to report's section collection
        reportObj.ReportSettings.Margin = new Thickness(0, 0, 0, 0);
        EmbeddedVisualReportSection section = new EmbeddedVisualReportSection(datagdStatus);
        reportObj.Sections.Add(section);
        var xamReportPreviewToGetTotalPageNumbers = new XamReportPreview();
        xamReportPreviewToGetTotalPageNumbers.GeneratePreview(reportObj, false, false);
        reportObj.PageFooterTemplate = GetDataTemplateForTotalPageNumbers(reportObj.PhysicalPageNumber);
        reportObj.Print(true, false);
        rteventLogger.WriteLog(TraceEventType.Information, "All Status report is printed", WMSTrace.ScopeTypes.Internal);
    }
    else
    {
        MessageBoxHelper.Show("No content available to print", MessageBoxImage.Information);
    }
}

GetDataTemplateForTotalPageNumbers如下:

private DataTemplate GetDataTemplateForTotalPageNumbers(int totalPages)
{
    var dataTemplate = new DataTemplate();
    //set up the label
    var labelFactory = new FrameworkElementFactory(typeof (Label)) {Name = "FooterLabel"};
    labelFactory.SetValue(VisibilityProperty, Visibility.Collapsed);
    labelFactory.SetValue(ContentProperty, new Binding());
    dataTemplate.VisualTree = labelFactory;
    var dataTrigger = new DataTrigger
    {
        Binding = new Binding("PhysicalPageNumber")
        {
            RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor)
            {
                AncestorType = typeof (ReportPagePresenter)
            }
        },
        Value = totalPages
    };
    dataTrigger.Setters.Add(new Setter {
        TargetName = "FooterLabel",
        Property = VisibilityProperty,
        Value = Visibility.Visible
    });
    dataTemplate.Triggers.Add(dataTrigger);
    return dataTemplate;
}

我希望这有所帮助。不过,我会谨慎使用它。因为现在我们生成报表两次(一次用于获取总页码并设置正确的数据模板,该模板在正确的页面上显示页脚,再次打印它)它会导致两次时间,所以如果你有一个巨大的网格,这会冻结 UI 一段时间。

相关内容

  • 没有找到相关文章

最新更新