WinFormsXaml 0.1.15
dotnet add package WinFormsXaml --version 0.1.15
NuGet\Install-Package WinFormsXaml -Version 0.1.15
<PackageReference Include="WinFormsXaml" Version="0.1.15" />
<PackageVersion Include="WinFormsXaml" Version="0.1.15" />
<PackageReference Include="WinFormsXaml" />
paket add WinFormsXaml --version 0.1.15
#r "nuget: WinFormsXaml, 0.1.15"
#:package WinFormsXaml@0.1.15
#addin nuget:?package=WinFormsXaml&version=0.1.15
#tool nuget:?package=WinFormsXaml&version=0.1.15
WinFormsXaml
WinFormsXaml creates normal Windows Forms control trees from readable XML. It targets .NET Framework 2.0 and has no runtime package dependencies.
Vibe-coding disclaimer: This project is vibe coded and was developed with extensive AI assistance. Review and test the source, generated behavior, and security assumptions for your own application before relying on it in production, especially on legacy Windows targets.
The package adds:
- one-way, reactive, and two-way bindings;
- stack, grid, dock, canvas, and flex layout;
- live presets for themes and other shared values;
- reusable XML and C# components;
- includes for shared presets, resources, and markup;
- styleable LTR/RTL tabs and scrollbars;
- observable item collections and opt-in virtualization;
- a packaged XSD for Visual Studio XML IntelliSense.
Create an embedded form
Keep each XML form beside a small C# code-behind class:
MyProduct/
Program.cs
WinFormsXaml.xsd
UI/
MainForm.cs
MainForm.xml
WinFormsXaml does not add application XML files to the build automatically.
Open the application's .csproj file as text and manually add this
ItemGroup inside the root <Project> element:
<ItemGroup>
<EmbeddedResource Include="UI\*.xml" />
</ItemGroup>
In Visual Studio, the equivalent is selecting each XML file in Solution Explorer, opening Properties, and setting Build Action to Embedded Resource.
UI/MainForm.xml:
<Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../WinFormsXaml.xsd"
Class="MyProduct.UI.MainForm"
Text="Example"
Width="520"
Height="320"
StartPosition="CenterScreen">
<StackPanel Margin="12">
<Label Text="{Binding Message}" AutoSize="true" />
<TextBox Text="{Binding Message, Mode=TwoWay}" Margin="0,8,0,8" />
<Button Text="Update" Click="UpdateButton_Click" />
</StackPanel>
</Form>
UI/MainForm.cs:
using System;
using WinFormsXaml;
namespace MyProduct.UI
{
public sealed class MainForm : XmlForm
{
public readonly PropertyBinding<string> Message =
new PropertyBinding<string>("Ready");
public MainForm()
: base("MainForm.xml")
{
}
private void UpdateButton_Click(object sender, EventArgs e)
{
Message.Value = "Updated";
}
}
}
Run it through the normal WinForms entry point:
using System;
using System.Windows.Forms;
using MyProduct.UI;
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new MainForm().Start();
}
}
XamlRuntime.Register() is not needed for this root-only example. It is used
for registered embedded components and includes, as shown below; XmlForm
loads the root Form directly.
The explicit base("MainForm.xml") call performs a partial embedded-resource
lookup. Use a longer fragment when an assembly contains duplicate filenames.
The constructor can be omitted only when the resource name exactly follows the
Derived.Type.FullName.xml convention.
XmlForm.WinForm is the native System.Windows.Forms.Form. Loading is lazy,
so initialize binding fields before accessing WinForm, Ui, Get<T>, or
Presets from a constructor.
Choose the state type
Use a public field for a snapshot that changes only at an explicit reload:
public string HeadingText = "My tasks";
private void RenameHeading()
{
HeadingText = "Open tasks";
ReloadBinding("Heading", "Text");
}
Use one stable PropertyBinding<T> for reactive or two-way state:
public readonly PropertyBinding<bool> Enabled =
new PropertyBinding<bool>(true);
<CheckBox Text="Enabled"
Checked="{Binding Enabled, Mode=TwoWay}" />
Changing .Value updates every target. Supported user edits update the same
binding and raise its change event.
Repeat data
Bind ItemsControl.ItemsSource to ItemsBinding<T>:
public readonly ItemsBinding<ResultRow> Results =
new ItemsBinding<ResultRow>();
<ItemsControl Name="Results" ItemsSource="{Binding Results}">
<ItemsControl.ItemTemplate>
<Label Text="{Binding Title}" AutoSize="true" />
</ItemsControl.ItemTemplate>
</ItemsControl>
Add, Remove, and Replace publish collection changes. Use
ReloadItem(index) after an unobserved item change and ReloadItems() when
every row must reevaluate. ScrollIntoView and ScrollIndexIntoView support
nearest, start, center, and end alignment.
AutoScroll defaults to true. SmoothScroll and viewport virtualization
default to false; enable either only when its behavior suits the workload.
Use presets
Presets can switch any supported property, not only colors:
<Form>
<Presets Name="Theme" Selected="Light" Default="Light">
<Preset Name="Light">
<Set Key="Surface" Value="White" />
<Set Key="Text" Value="Black" />
</Preset>
<Preset Name="Dark">
<Set Key="Surface" Value="#23272E" />
<Set Key="Text" Value="#F3F5F7" />
</Preset>
</Presets>
<StackPanel BackColor="{Preset Theme.Surface}">
<Label Text="Welcome" ForeColor="{Preset Theme.Text}" />
</StackPanel>
</Form>
Presets.Select("Theme", "Dark");
If the selected variant omits a key, the declared default variant is used. If neither defines it, the target returns to its original non-preset value.
Reuse markup
Before loading a form that uses embedded XML components or registered includes, register those reusable documents once during application startup:
XamlRuntime.Register();
new MainForm().Start();
The scan registers only Component and Includes roots. It safely ignores the
root Form, which XmlForm loads directly.
- Register embedded
ComponentandIncludesdocuments withXamlRuntime.Register(). - Use
<Component>for reusable XML control trees with bindable properties and projected<Children />. - Use
<Includes Source="SharedTheme" />to merge shared presets, resources, components, or ordinary child markup. - Use
TabViewfor fully styleable tabs andFlexPanelfor CSS-like rows, columns, wrapping, gaps, alignment, and growth. - Use
HyperlinkLabelfor a LinkLabel that opens a URI through the default shell handler. - Use
Imagefor WPF-style source/stretch authoring or nativePictureBoxwhen its standard API is preferred.
XML IntelliSense
The package exposes WinFormsXaml.xsd as a linked project-root file. Associate
an XML form using:
<Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../WinFormsXaml.xsd">
The schema covers built-in controls, framework elements, properties, events, enum values, and expression-capable attributes. Runtime-registered custom CLR types remain valid even when a static XSD cannot enumerate their members.
Compatibility and trust
The runtime is compiled as C# 2.0 against .NET Framework 2.0 reference assemblies. Modern Windows, Wine, Mono, and Windows 98 are separate validation environments; success in one is not proof for another.
Markup can instantiate types, assign properties, resolve local resources, and connect code-behind methods. Treat XML and preset files as application code and do not load untrusted uploaded or network-provided markup directly.
Package contents
lib/net20/WinFormsXaml.dlllib/net20/WinFormsXaml.pdblib/net20/WinFormsXaml.xmlWinFormsXaml.xsdfor PackageReference and classic projects- this package README
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net20 is compatible. net35 was computed. net40 was computed. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.