Pysar.Xaml
0.1.63
dotnet add package Pysar.Xaml --version 0.1.63
NuGet\Install-Package Pysar.Xaml -Version 0.1.63
<PackageReference Include="Pysar.Xaml" Version="0.1.63" />
<PackageVersion Include="Pysar.Xaml" Version="0.1.63" />
<PackageReference Include="Pysar.Xaml" />
paket add Pysar.Xaml --version 0.1.63
#r "nuget: Pysar.Xaml, 0.1.63"
#:package Pysar.Xaml@0.1.63
#addin nuget:?package=Pysar.Xaml&version=0.1.63
#tool nuget:?package=Pysar.Xaml&version=0.1.63
Pysar.Xaml
Declarative report markup for Pysar, a cross-platform report
engine for .NET: this package contains the runtime .rxaml loader and the code-behind source
generator. It depends on the core Pysar package, which carries the element tree, data binding and
the SkiaSharp rendering and PDF engine.
.rxaml is Pysar's markup dialect: an XML document that describes a report the same way the fluent
builder does, using the same elements (Grid, StackPanel, Frame, Text, Image, Repeater)
and the same bands. It is the better fit for a report with a fixed shape — an invoice, a statement, a
certificate — because the layout stays readable as a tree instead of a chain of method calls, and it
is what makes a report editable by someone who is not writing C#: a template stored in a database, or
edited through the design-time preview in Rider and VS Code.
<Report xmlns="https://mriyalab.com/pysar" x:DataType="local:Invoice">
<PageFormat Size="A4" Margin="30" />
<ReportHeaderBand>
<Text Content="{Binding Company.Name}" FontSize="18" FontStyle="Bold" />
</ReportHeaderBand>
<DetailBand DataSource="{Binding Items}">
<DetailBand.DetailHeader>
<Text Content="Product" FontStyle="Bold" />
</DetailBand.DetailHeader>
<Grid ColumnDefinitions="*, 80, 80">
<Text Grid.Column="0" Content="{Binding Product}" />
<Text Grid.Column="1" Content="{Binding Quantity}" />
<Text Grid.Column="2" Content="{Binding Total, StringFormat='{0:C}'}">
<Text.Triggers>
<DataTrigger Binding="{Binding Total}" CompareType="GreaterThan" Value="1000">
<Setter Member="FontColor" Value="Chocolate" />
</DataTrigger>
</Text.Triggers>
</Text>
</Grid>
</DetailBand>
</Report>
An .rxaml report supports the same binding system as the object model: {Binding Path} against the
element's data context, string formats, value converters, and DataTrigger for conditional
formatting. A DataSource on DetailBand (or any Repeater) puts its children in a per-item scope
over the bound collection, with an optional DetailHeader and DetailFooter that stay in the outer
scope.
Loading at runtime
Reports can be loaded at runtime, which is what a template stored in a database or edited by a user needs:
using Pysar.Xaml;
var report = ReportXaml.Load("""
<Report xmlns="https://mriyalab.com/pysar">
<PageFormat Size="A4" Margin="30" />
<DetailBand>
<Text Content="Hello from XAML" />
</DetailBand>
</Report>
""");
report.Build();
Code-behind source generator
For application projects, the source generator uses the standard x:Class directive to provide
generated InitializeComponent(), strongly typed x:Name fields, and compiled object construction.
The generator ships inside this package as an analyzer and is wired up automatically through
build/Pysar.Xaml.props — no separate analyzer reference is needed. Every .rxaml file in the
project is picked up automatically; set <EnableDefaultReportItems>false</EnableDefaultReportItems>
to list them yourself. Resources, styles, and triggers currently use the runtime-loader fallback.
Compile-time binding validation
Any element accepts the MAUI-style directive x:DataType="local:Invoice" to declare the
data-context type of a scope. The hint is design-time only — it is ignored when the report is
loaded — and is inherited by child elements until another element declares its own;
x:DataType="" clears it for that subtree. The source generator validates {Binding ...} paths —
and DataTrigger.Binding — against the hint at build time (PQX010 error for an unknown member,
PQX011 warning for a type it cannot resolve). Where the scope cannot be known, nothing is reported
rather than guessed: styles and resource dictionaries are reused across scopes, so their bindings are
never validated. The XAML designer idiom d:DataContext="{d:DesignInstance Type=local:Invoice}" is
an accepted alternative spelling of the same hint, used when no x:DataType is present on the
element.
Documentation
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- HarfBuzzSharp (>= 14.2.1.1)
- HarfBuzzSharp.NativeAssets.Linux (>= 14.2.1.1)
- HarfBuzzSharp.NativeAssets.macOS (>= 14.2.1.1)
- HarfBuzzSharp.NativeAssets.Win32 (>= 14.2.1.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Pysar (>= 0.1.63)
- SkiaSharp (>= 4.151.2)
- SkiaSharp.NativeAssets.Linux (>= 4.151.2)
- SkiaSharp.NativeAssets.macOS (>= 4.151.2)
- SkiaSharp.NativeAssets.Win32 (>= 4.151.2)
- Svg.Skia (>= 5.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## Avalonia fonts
**Report fonts can come from Avalonia `FontManager`.**
`UsePysar` installs a typeface fallback before your configuration. The family string in the report must be the Avalonia `FontFamily` string — `fonts:Inter#Inter` after `WithInterFont`, or `avares://MyApp/Fonts#Ubuntu` for a resource folder — not a file path. A bare name is a system-font lookup; if `TryGetGlyphTypeface` substitutes Helvetica, Pysar treats that as a miss.
`AddFont` still wins. A library `ReportAsset` still needs one `AddFont`: the file is not copied into the head, and `FontManager` does not see it. A XAML `FontFamily` resource is not a registration. Styles stay `Normal`, `Bold`, `Italic` and `BoldItalic`. This bridge is Avalonia only. Console, the design-time preview, MAUI, WPF and Uno keep `AddFont`.
## PDF export
**PDF/A-2b is an option of PDF, not another format.**
Pass `new PdfExportOptions { PdfA = true }` to `SavePdfAsync`, `RenderToPdfAsync`, `RenderToPdfBytesAsync`, or `IReportExportService.ExportAsync`. Skia writes the archival document setup: XMP `pdfaid` identification, a document UUID, and an sRGB output intent. It does not validate the file. A font Skia cannot embed still fails a checker, and the UUID makes those bytes non-reproducible. Existing overloads are unchanged.
## Images
**SVG is drawn from the bytes, not only from a `.svg` path.**
A stream or embedded source whose bytes start with `<svg` (optional XML declaration) is rendered as SVG. A decode or parse failure is recorded on the image cache, so the same bad bytes are not decoded again. Fixes #23.
## Rendering
**A built report may be rendered more than once, only sequentially.**
PDF and then page bitmaps, or a retry of the same export, is supported. Do not render one instance concurrently. `PageNumber` and `PageCount` are scratch written during the pass, and `OnPageChanged` runs again on every render.
## Uno
**Android report pages no longer depend on OpenGL ES.**
`UsePysar` sets `UseOpenGLOnSkiaAndroid` to false before the window is created. OpenGL ES draws image textures as opaque black, which hid every report page.
## Internal
- Host startup (Avalonia, MAUI, WPF, Uno) shares one installation sequence, `PysarInstallation`.
- `InternalsVisibleTo` for `Pysar.Avalonia` and `Pysar.Avalonia.Tests`.
**Full changelog:** v0.1.56...HEAD