OutWit.Common.MVVM.WPF.Generator
2.0.2
See the version list below for details.
dotnet add package OutWit.Common.MVVM.WPF.Generator --version 2.0.2
NuGet\Install-Package OutWit.Common.MVVM.WPF.Generator -Version 2.0.2
<PackageReference Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="OutWit.Common.MVVM.WPF.Generator" Version="2.0.2" />
<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.2
#r "nuget: OutWit.Common.MVVM.WPF.Generator, 2.0.2"
#:package OutWit.Common.MVVM.WPF.Generator@2.0.2
#addin nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.2
#tool nuget:?package=OutWit.Common.MVVM.WPF.Generator&version=2.0.2
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
Non-Commercial License (NCL) - Free for personal, educational, and research purposes.
For commercial use, contact licensing@ratner.io.
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.