2013-04-04 69 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

相關問題