Rendering Project Data to XAML
Overview
XAML (Extensible Application Markup Language) is a declarative XML-based language used primarily for defining user interfaces in .NET-based technologies like WPF and UWP. Aspose.Tasks for .NET allows developers to export Microsoft Project data (MPP, XML) to XAML format, which can then be embedded in desktop applications, printed, or further customized using WPF/XAML toolkits.
This feature is useful when:
- You want to display project data in a rich UI using WPF;
- You plan to embed read-only Gantt views in a desktop system;
- You need platform-neutral vector output for rendering project views at high fidelity.
Supported Output Views
The PresentationFormat
enumeration defines supported view types when exporting to XAML:
GanttChart
– shows tasks and their timelines;TaskUsage
– presents assignments and work per task;ResourceUsage
– details workload distribution per resource;ResourceSheet
– tabular view of resources.
These can be combined with display options to fully customize output.
Rendering to XAML with Save Options
To render a project file to XAML:
- Create an instance of
XamlOptions
; - Configure layout, view, and display settings:
FitContent
: ensures the content fits into view;LegendOnEachPage
: toggles legend visibility;Timescale
: sets granularity (e.g., Days, Weeks);View
: defines the layout and columns to include;
- Save the project using
Project.Save()
withSaveFileFormat.XAML
.
Example 1: Basic Save to XAML
1Project project = new Project("New Project.mpp");
2project.Save("RenderToXAML_out.xaml", SaveFileFormat.XAML);
Advanced Usage: Customizing View Options
Aspose.Tasks allows fine-grained customization of the XAML output. You can define:
- Which columns are shown using
GanttChartColumn
; - What font, text alignment, or column widths to apply;
- Whether to include non-working time or roll-up tasks.
Example 2: Export XAML with View Options
1Project project = new Project("New Project.mpp");
2SaveOptions options = new XamlOptions();
3options.FitContent = true;
4options.LegendOnEachPage = false;
5options.Timescale = Timescale.ThirdsOfMonths;
6project.Save("RenderXAMLWithOptions_out.xaml", options);
Rendering with Different Presentation Formats
You can choose different data perspectives when exporting to XAML using the PresentationFormat
property.
Example 3: Export TaskUsage, ResourceUsage, and Gantt views
1Project project = new Project("New Project.mpp");
2SaveOptions options = new XamlOptions();
3options.PresentationFormat = PresentationFormat.GanttChart;
4project.Save("RenderDifferentPresentationFormatsToXAML_out.xaml", options);
Summary
Exporting project data to XAML using Aspose.Tasks for .NET opens up powerful integration capabilities with WPF/XAML-based desktop applications. The output is vector-based, resolution-independent, and ready to be styled and displayed dynamically.
🔗 See also: