Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.67 KB

WPF0041.md

File metadata and controls

51 lines (37 loc) · 1.67 KB

WPF0041

Set mutable dependency properties using SetCurrentValue.

Topic Value
Id WPF0041
Severity Warning
Enabled True
Category WpfAnalyzers.DependencyProperty
Code WPF0041SetMutableUsingSetCurrentValue

Description

Prefer setting mutable dependency properties using SetCurrentValue.

Motivation

Setting the value of dependency properties using the CLR accessor calls SetValue(Property, value). This will kill one-way bindings on the property. This rule is probably most relevant in library code where accidentally setting a value can be a hard to track down bug.

How to fix violations

Use SetCurrentValue(Property, value)

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable WPF0041 // Set mutable dependency properties using SetCurrentValue.
Code violating the rule here
#pragma warning restore WPF0041 // Set mutable dependency properties using SetCurrentValue.

Or put this at the top of the file to disable all instances.

#pragma warning disable WPF0041 // Set mutable dependency properties using SetCurrentValue.

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("WpfAnalyzers.DependencyProperty", 
    "WPF0041:Set mutable dependency properties using SetCurrentValue.", 
    Justification = "Reason...")]