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
<PackageReference Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.4"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.4" />
<PackageReference Include="OutWit.Common.MVVM.WPF.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add OutWit.Common.MVVM.WPF.Generator --version 2.0.4
#r "nuget: OutWit.Common.MVVM.WPF.Generator, 2.0.4"
#:package OutWit.Common.MVVM.WPF.Generator@2.0.4
#addin nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.4
#tool nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.4
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:
Finds Properties - Scans your code for properties marked with:
[StyledProperty]- generates instanceDependencyProperty[AttachedProperty]- generates attachedDependencyProperty
Generates Code - Creates:
public static readonly DependencyPropertyfields- Property getter/setter implementations using
GetValue/SetValue Get{PropertyName}andSet{PropertyName}methods for attached propertiesPropertyMetadataorFrameworkPropertyMetadatawith specified options
Convention-Based Discovery - Automatically finds callback methods:
On{PropertyName}Changedfor PropertyChangedCallback{PropertyName}Coercefor 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
DependencyPropertyboilerplate - Compile-time generation
- Full IntelliSense support
?? Convention-Based Callbacks
- Automatically finds
On{PropertyName}Changedmethods - Automatically finds
{PropertyName}Coercemethods
?? Metadata Options
AffectsMeasure,AffectsArrange,AffectsRenderBindsTwoWayByDefault,InheritsPropertyChangedCallback,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
- Clean and rebuild:
dotnet clean && dotnet build - Ensure class is marked as
partial - Check using directive:
using OutWit.Common.MVVM.WPF.Attributes;
View Generated Files
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Related Packages
- 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!
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.