xmlns:igDP="http://infragistics.com/DataPresenter"
Report オブジェクトをインスタンス化して EmbeddedVisualReportSection オブジェクトをその Sections コレクションに追加してからでなければ、レポートをプレビュー、印刷、またはエクスポートすることはできません。セクションを Report オブジェクトに追加した後で、xamReportPreview™ コントロールを使用してレポートの 印刷プレビューを表示したり、XML Paper Specification (XPS) 形式でレポートをエクスポートしたり、レポートをプリンタに出力することができます。
主要コンテンツとして xamDataGrid™ を使用してレポートを作成します。
xamReportPreview をウィンドウに追加します。
Microsoft® Windows® Presentation Foundation Window プロジェクトを作成します。
ソリューション エクスプローラーで以下の NuGet パッケージ参照をプロジェクトに追加します。NuGet フィードのセットアップと NuGet パッケージの追加の詳細については、NuGet フィード ドキュメントを参照してください。
Infragistics.WPF.Reporting
Infragistics.WPF.DataGrids
アプリケーションにレポート機能を実装するには、上記のリストのうち、最初のパッケージへの参照のみが必要です。XamDataGrid コントロールは、このトピックの残りの部分でレポート機能を紹介するために使用されます。
開いている Window タグ内で XamDataGrid の名前空間宣言を追加します。
XAML の場合:
xmlns:igDP="http://infragistics.com/DataPresenter"
DockPanel コンテナーを Window に追加します。
XAML の場合:
<DockPanel>
<!--TODO: ここに Button を追加します。-->
<!--TODO: ここに xamDataGrid を追加します。-->
</DockPanel>
Button コントロールを DockPanel コンテナーに追加します。
添付の DockPanel.Dock プロパティを Top に設定します。
Content プロパティを "Print xamDataGrid" に設定します。
Button コントロールの Click イベントにイベント ハンドラーを接続します。
XAML の場合:
<Button
DockPanel.Dock="Top"
Content="Print xamDataGrid"
Click="Button_Click" />
xamDataGrid を DockPanel コンテナーに追加します。
Name プロパティを設定すると、コード ビハインドで参照できます。
BindToSampleData プロパティを True に設定します。
XAML の場合:
<igDP:XamDataGrid Name="xamDataGrid1" BindToSampleData="True" />
コード ビハインドを開き、コード ビハインド内に using/Imports のディレクティブを配置すれば、メンバーの完全に記述された名前を常にタイプする必要がなくなります。
Visual Basic の場合:
Imports Infragistics.Windows.Reporting
C# の場合:
using Infragistics.Windows.Reporting;
Visual Basic の場合:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim report1 As New Report()
Dim section1 As New EmbeddedVisualReportSection(Me.xamDataGrid1)
report1.Sections.Add(section1)
report1.Print()
' 以下のコード行は、xamDataGrid のコンテンツを
' XPS ドキュメントにエクスポートします。
'report1.Export(OutputFormat.XPS, "c:\\xamDataGrid1.xps")
End Sub
C# の場合:
private void Button_Click(object sender, RoutedEventArgs e)
{
Report report1 = new Report();
EmbeddedVisualReportSection section1 = new EmbeddedVisualReportSection(this.xamDataGrid1);
report1.Sections.Add(section1);
report1.Print();
// 以下のコード行は、xamDataGrid のコンテンツを
// XPS ドキュメントにエクスポートします。
//report1.Export(OutputFormat.XPS, "c:\\xamDataGrid1.xps");
}
プロジェクトを実行します。
以下のスクリーンショットのような Window が表示されます。"Print xamDataGrid" とラベルが付けられたボタンをクリックして、xamDataGrid コントロールのコンテンツを印刷できます。
Microsoft® Windows® Presentation Foundation Window プロジェクトを作成します。
以下の NuGet パッケージ参照をプロジェクトに追加します。
Infragistics.WPF.Reporting
NuGet フィードのセットアップと NuGet パッケージの追加の詳細については、NuGet フィード ドキュメントを参照してください。
Infragistics 名前空間宣言を追加します。
XAML の場合:
xmlns:igReporting="http://infragistics.com/Reporting"
Visual Basic の場合:
Imports Infragistics.Windows.Reporting
C# の場合:
using Infragistics.Windows.Reporting;
デフォルトの Grid レイアウト コンテナーに名前を付けると、コード ビハインドで参照できます。
XAML の場合:
<Grid Name="layoutRoot"> </Grid>
コード ビハインドを使用する場合、Window の Loaded イベントにイベント ハンドラーを接続します。
XAML の場合:
<Window ... Loaded="Window_Loaded">
xamReportPreview コントロールのインスタンスを作成して、これをメイン Grid に追加します。
XAML の場合:
<igReporting:XamReportPreview Name="xamReportPreview1" />
Visual Basic の場合:
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim xamReportPreview1 = New XamReportPreview()
Me.layoutRoot.Children.Add(xamReportPreview1)
End Sub
C# の場合:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
XamReportPreview xamReportPreview1 = new XamReportPreview();
this.layoutRoot.Children.Add(xamReportPreview1);
}
プロジェクトを実行します。
プロジェクトを実行すると、以下のスクリーンショットに似た Window が表示されます。xamReportPreview コントロールは、レポートのプレビューを生成していないために、コンテンツを表示しません。xamReportPreview の GeneratePreview メソッドを呼び出し、 Report オブジェクトに参照を渡す必要があります。