OutWit.Common.MVVM 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package OutWit.Common.MVVM --version 1.0.0                
NuGet\Install-Package OutWit.Common.MVVM -Version 1.0.0                
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" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OutWit.Common.MVVM --version 1.0.0                
#r "nuget: OutWit.Common.MVVM, 1.0.0"                
#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.
// Install OutWit.Common.MVVM as a Cake Addin
#addin nuget:?package=OutWit.Common.MVVM&version=1.0.0

// Install OutWit.Common.MVVM as a Cake Tool
#tool nuget:?package=OutWit.Common.MVVM&version=1.0.0                

Simplifying DependencyProperty Management with the Bindable Aspect

When working with WPF, dealing with DependencyProperty can be tedious and error-prone. Typically, you need to:

  1. Declare the static DependencyProperty:
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(int), typeof(MyControl),
            new PropertyMetadata(0, new PropertyChangedCallback(OnValueChanged)));
    
  2. Create a property for accessing the value:
    public int Value
    {
       get => (int)GetValue(ValueProperty);
       set => SetValue(ValueProperty, value);
    }
    

This boilerplate code is verbose and introduces multiple opportunities for errors.

Using BindingUtils for Cleaner Registration

The BindingUtils utility makes DependencyProperty registration more concise:

public static readonly DependencyProperty ValueProperty =
    BindingUtils.Register<MyControl, int>(nameof(Value), OnValueChanged); 

This utility reduces boilerplate and improves readability.

Eliminating GetValue and SetValue with the Bindable Aspect

The Bindable aspect simplifies property definitions further by eliminating the need to explicitly call GetValue and SetValue. For example:

[Bindable]
public int Value { get; set; }

This reduces the code significantly, making classes cleaner and easier to maintain.

Customizing DependencyProperty Names

By default, the aspect assumes the DependencyProperty for a property named [Name] is declared as [Name]Property. For instance, a property named Value is expected to use ValueProperty.

If the DependencyProperty uses a custom name, you can specify it explicitly:

[Bindable("CustomDependencyProperty")]
public int Value { get; set; }

Key Benefits

  • Reduces repetitive code.
  • Ensures consistency and readability.
  • Simplifies working with DependencyProperty in WPF applications.

For more details, check out the article.

Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.1 95 11/24/2024
1.0.0 92 10/13/2024