0

我试着PrintList of objectsCrystal Report所以我创建了一个 WPF 窗口,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace Winlease.UI
{
    /// <summary>
    /// Logique d'interaction pour EcheancierPrint.xaml
    /// </summary>
    public partial class EcheancierPrint : Window
    {
        List<T> ListToPrint = null;

        public EcheancierPrint(List<T> lst) : base()
        {
            ListToPrint = lst;
        }

        public EcheancierPrint()
        {
            InitializeComponent();
        }

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            ReportDocument rd = new ReportDocument();
            rd.Load("../../Echeancier.rpt");
            rd.SetDataSource(ListToPrint);
        }
    }
}

这个窗口是从另一个窗口中按钮的 Click 事件处理程序调用的,这里的代码:

private void cmdPrint_Click(object sender, RoutedEventArgs e)
{
    EcheancierPrint pe = new EcheancierPrint(echeancier);
}

Echeancier是一个List of ObjectEcheance。类型“T”和方法InitializeComponent变为红色下划线,并且不被 WPF 编译器接受。指令的相同行为:

EcheancierPrint pe = new EcheancierPrint(echeancier);
4

1 回答 1

0

如果T不是具体类型,则必须声明EcheancierPrint为泛型类型EcheancierPrint<T>,但当前 XAML 不支持泛型。(XAML 2009 支持但不支持已编译的 XAML)。
此外,在您的情况下,类型是开放的泛型类型。

您真的需要将演示对象(UI 控件)与业务对象混合吗?

于 2013-04-04T15:59:32.240 回答