Dynamically create a Table in XAML

2013-10-25

Sometimes when we develop the WPF applications we need create tables with different configurations for output any data. Using the base tools of Visual Studio or Blend do not allow to reach the desired result or not always possible.

XAML Report

Objects can be added programmatically to the form directly in the program code during execution.

Plus this method is in using a minimum set of software. But the construction of a large table it will take too much time. Also we need to implement access to the tables with the data. A further change in the structure will have to rebuild all over again.

Other way to get a beautiful custom table - using FastReport.NET.

Open the report designer, create a data source and add objects: the title of the report, the page header, the data pages and other objects if desired. Then we make a preview of the report and save it in XAML. Now you need save a created report template for future use.

You can embed FastReport.NET to the own application. First step: open report from code and export it in the XAML. In second step you need to load XAML into your WPF application.

Example:

// prepare a report
report1.Prepare();
// create an instance of XAML export filter
FastReport.Export.XAML.XAMLExport export = new FastReport.Export.XAML.XAMLExport();
// export in xaml
report1.Export(export, "result.xaml"); 

Let’s load a table in WPF:

// / Create a stream to read the selected XAML file
using (FileStream fs = new FileStream(filename, FileMode.Open))
{ // Create a new window for graphics output XAML content file
 ((Window)XamlReader.Load(fs)).Show();
}

Where filename - the name of the file you created with the table.

Instead FileStream, you can use the MemoryStream, then the XAML can be transferred without the use of files.

As you see we build a table directly in the program code. It allows you to generate a table on the server side and on use the client to render the XAML.

FastReport.NET eliminates the writing a database access code and reduces overall development time. Also we have saved template of the table for future modifications.

.NET .NET Visual Studio Visual Studio FastReport FastReport WPF WPF
April 08, 2025

How to Set Up a Connection to Apache Ignite in FastReport .NET

In this article, we will explore how to configure a connection to Apache Ignite in FastReport .NET. You will learn the necessary steps to connect the plugin via code and the report designer.
April 08, 2025

Converter from Microsoft Word (.docx) format to FastReport .NET (.frx) file

A converter from Microsoft Word (.docx) format to a file FastReport .NET (.frx): description and instructions for using the tool.
March 25, 2025

How to Merge Multiple Reports into One in FastReport .NET

FastReport .NET is a powerful tool for creating and managing reports. In this article, we will look at how to combine multiple reports into one in FastReport .NET.
Fast Reports
  • 800-985-8986 (English, US)
  • +31 97 01025-8466 (English, EU)
  • +49 30 56837-3928 (German, DE)
  • +55 19 98147-8148 (Portuguese, BR)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2025 Fast Reports Inc.