The WPF0003 analyzer ensures that the name of a CLR property accessor matches the name used when registering its corresponding DependencyProperty. While technically legal to use different names, mismatching them creates a confusing API that violates standard WPF conventions.
Violation Example:
In the example below, the DependencyProperty is registered as Title, but the CLR property is named HighlightBrush.
using System.Windows;
public class MyControl : FrameworkElement
{
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
nameof(Title),
typeof(string),
typeof(MyControl),
new PropertyMetadata(default(string)));
public string HighlightBrush
{
get { return (string)this.GetValue(TitleProperty); }
set { this.SetValue(TitleProperty, value); }
}
}
Correct Implementation:
Rename the CLR property to match the registered name (Title).
using System.Windows;
public class MyControl : FrameworkElement
{
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
nameof(Title),
typeof(string),
typeof(MyControl),
new PropertyMetadata(default(string)));
public string Title
{
get { return (string)this.GetValue(TitleProperty); }
set { this.SetValue(TitleProperty, value); }
}
}