Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top

Webinar: Let's make a programming language. Part 1. Intro - 20.02

>
>
>
V3049. WPF: readonly field of...
menu mobile close menu
Additional information
toggle menu Contents

V3049. WPF: readonly field of 'DependencyProperty' type is not initialized.

20 Jan 2016

The analyzer detected a possible error related to dependency property registration. A dependency property was defined but wasn't initialized: it will cause an error when trying to access the property using SetValue / GetValue.

class A : DependencyObject
{
  public static readonly DependencyProperty CurrentTimeProperty;
  static A(){ /* CurrentTimeProperty not initialized */ }
      ....

Bad refactoring or copy-paste may result in leaving a dependency property unregistered. The following is the fixed version of the code above:

class A : DependencyObject
{
public static readonly DependencyProperty CurrentTimeProperty;
static A()
{
  CurrentTimeProperty =
    DependencyProperty.Register("CurrentTime", typeof(DateTime),
                                typeof(A));
}
....