OutWit.Common.MVVM
1.0.0
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
<PackageReference Include="OutWit.Common.MVVM" Version="1.0.0" />
<PackageVersion Include="OutWit.Common.MVVM" Version="1.0.0" />
<PackageReference Include="OutWit.Common.MVVM" />
paket add OutWit.Common.MVVM --version 1.0.0
#r "nuget: OutWit.Common.MVVM, 1.0.0"
#:package OutWit.Common.MVVM@1.0.0
#addin nuget:?package=OutWit.Common.MVVM&version=1.0.0
#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:
- Declare the static
DependencyProperty:public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(MyControl), new PropertyMetadata(0, new PropertyChangedCallback(OnValueChanged))); - 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 | Versions 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. net10.0-windows was computed. |
-
net5.0-windows7.0
- OutWit.Common.Logging (>= 1.0.0)
-
net6.0-windows7.0
- OutWit.Common.Logging (>= 1.0.0)
-
net7.0-windows7.0
- OutWit.Common.Logging (>= 1.0.0)
-
net8.0-windows7.0
- OutWit.Common.Logging (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.