C# 如何将通用列表传递给WPF窗口
我尝试将C# 如何将通用列表传递给WPF窗口,c#,wpf,list,generics,crystal-reports,C#,Wpf,List,Generics,Crystal Reports,我尝试将对象列表打印到Crystal 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 S
对象列表打印到Crystal 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);
}
}
}
Echeancier
是一个名为Echeance
的对象列表。类型“T”和方法InitializeComponent用红色下划线,WPF编译器不接受。指令的相同行为:
EcheancierPrint pe = new EcheancierPrint(echeancier);
如果T
不是具体类型,则必须将EcheancierPrint
声明为泛型类型EcheancierPrint
,但当前XAML不支持泛型。(XAML 2009不适用于已编译的XAML)。
此外,在您的案例中,类型是开放泛型类型
您真的需要将persentation对象(UI控件)与业务对象混合使用吗?Echeance业务对象是在另一个称为BLL的DLL程序集中定义的。现在,我通过如下方式指定实际类型来解决泛型类型的问题:public EcheancierPrint(List lst):base(){ListToPrint=lst;}关于InitializeComponent,它用红色下划线,因为我更改了名称空间,并且没有更新xaml文件。非常感谢。
EcheancierPrint pe = new EcheancierPrint(echeancier);