2013-04-04 68 views
0

我尝试使用Print a List of objectsCrystal Report。所以,我创建了一个WPF窗口如下:如何将通用列表传递给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一个名为EcheanceList of Object“T”和方法InitializeComponent被红色加下划线并且不被WPF编译器接受。对于指令相同的行为:

EcheancierPrint pe = new EcheancierPrint(echeancier); 

回答

0

如果T是不是你必须声明EcheancierPrint为通用型EcheancierPrint<T>但目前XAML不支持泛型具体类型。 (XAML 2009不支持编译XAML)。
此外在你的案例类型是开放的泛型类型。

你真的需要将persentation对象(UI控件)与业务对象混合吗?

+0

Echeance业务对象在另一个称为BLL的DLL程序集中定义。现在,我通过指定实际类型解决了泛型类型的问题,如下所示:public EcheancierPrint(List lst):base() { ListToPrint = lst; } – 2013-04-04 16:13:00

+0

关于InitializeComponent,它用红色下划线,因为我改变了命名空间,我没有更新xaml文件。谢谢 – 2013-04-04 16:15:33

相关问题