OutWit.Common.MVVM.WPF.Generator 2.0.4

dotnet add package OutWit.Common.MVVM.WPF.Generator --version 2.0.4
                    
NuGet\Install-Package OutWit.Common.MVVM.WPF.Generator -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.4">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Common.MVVM.WPF.Generator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OutWit.Common.MVVM.WPF.Generator --version 2.0.4
                    
#r "nuget: OutWit.Common.MVVM.WPF.Generator, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OutWit.Common.MVVM.WPF.Generator@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.4
                    
Install as a Cake Tool

OutWit.Common.MVVM.WPF.Generator

Roslyn Source Generator for automatic WPF DependencyProperty generation. This generator reads properties marked with [StyledProperty] or [AttachedProperty] attributes and generates the necessary DependencyProperty fields and implementations at compile time.

?? Important: Don't Install Directly

This package should NOT be installed directly! It's automatically included when you install OutWit.Common.MVVM.WPF.

# ? Correct - Install the WPF package
dotnet add package OutWit.Common.MVVM.WPF

# ? Wrong - Don't install the generator directly
dotnet add package OutWit.Common.MVVM.WPF.Generator

What It Does

This source generator:

  1. Finds Properties - Scans your code for properties marked with:

    • [StyledProperty] - generates instance DependencyProperty
    • [AttachedProperty] - generates attached DependencyProperty
  2. Generates Code - Creates:

    • public static readonly DependencyProperty fields
    • Property getter/setter implementations using GetValue/SetValue
    • Get{PropertyName} and Set{PropertyName} methods for attached properties
    • PropertyMetadata or FrameworkPropertyMetadata with specified options
  3. Convention-Based Discovery - Automatically finds callback methods:

    • On{PropertyName}Changed for PropertyChangedCallback
    • {PropertyName}Coerce for CoerceValueCallback

How It Works

Input (Your Code)

using System.Windows.Controls;
using OutWit.Common.MVVM.WPF.Attributes;

namespace MyApp.Controls
{
    public partial class CustomButton : Button
    {
        [StyledProperty(DefaultValue = "Click Me", AffectsMeasure = true)]
        public string Label { get; set; }

        [StyledProperty]
        public double IconSize { get; set; }

        // Convention: On{PropertyName}Changed
        private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var button = (CustomButton)d;
            button.UpdateLabel();
        }
    }
}

Output (Generated Code)

// <auto-generated/>
#nullable enable

namespace MyApp.Controls
{
    partial class CustomButton
    {
        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register(
                nameof(Label), 
                typeof(string), 
                typeof(CustomButton),
                new FrameworkPropertyMetadata(
                    "Click Me", 
                    FrameworkPropertyMetadataOptions.AffectsMeasure, 
                    OnLabelChanged));

        public static readonly DependencyProperty IconSizeProperty =
            DependencyProperty.Register(
                nameof(IconSize), 
                typeof(double), 
                typeof(CustomButton));
    }
}

Features

? Automatic Generation

  • No manual DependencyProperty boilerplate
  • Compile-time generation
  • Full IntelliSense support

?? Convention-Based Callbacks

  • Automatically finds On{PropertyName}Changed methods
  • Automatically finds {PropertyName}Coerce methods

?? Metadata Options

  • AffectsMeasure, AffectsArrange, AffectsRender
  • BindsTwoWayByDefault, Inherits
  • PropertyChangedCallback, CoerceValueCallback

?? Attached Properties

public static partial class MyAttachedProperties
{
    [AttachedProperty(DefaultValue = false)]
    public static bool IsHighlighted { get; set; }
}

Requirements

  • .NET SDK: 6.0 or later
  • Target Framework: net6.0-windows or later
  • Platform: WPF (Windows only)

Troubleshooting

Generated Code Not Appearing

  1. Clean and rebuild: dotnet clean && dotnet build
  2. Ensure class is marked as partial
  3. Check using directive: using OutWit.Common.MVVM.WPF.Attributes;

View Generated Files

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
  • OutWit.Common.MVVM.WPF - Main WPF package (install this!)
  • OutWit.Common.MVVM - Cross-platform base classes

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Attribution (optional)

If you use OutWit.Common.MVVM.WPF.Generator in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.MVVM.WPF.Generator (https://ratner.io/)".

Trademark / Project name

"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.

You may:

  • refer to the project name in a factual way (e.g., "built with OutWit.Common.MVVM.WPF.Generator");
  • use the name to indicate compatibility (e.g., "OutWit.Common.MVVM.WPF.Generator-compatible").

You may not:

  • use "OutWit.Common.MVVM.WPF.Generator" as the name of a fork or a derived product in a way that implies it is the official project;
  • use the OutWit.Common.MVVM.WPF.Generator logo to promote forks or derived products without permission.

Remember: This package is automatically included with OutWit.Common.MVVM.WPF. Don't install it separately!

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 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.

Version Downloads Last Updated
2.0.4 124 1/25/2026
2.0.3 118 1/8/2026
2.0.2 121 1/2/2026
2.0.1 116 1/2/2026
2.0.0 113 1/2/2026