Skip to content

Attributes

Lucas Trzesniewski edited this page Nov 4, 2021 · 8 revisions

AddINotifyPropertyChangedInterfaceAttribute

Specifies that the class will be marked with INotifyPropertyChanged. Note that all classes that implement INotifyPropertyChanged will have property notification injected irrespective of the use of this attribute.

Raising an issue about "this attribute does not behave as expected" will result in a RTFM and the issue being closed.

AlsoNotifyForAttribute

Allows the injection of notify code that points to a different property.

For example

public class Person : INotifyPropertyChanged
{
    [AlsoNotifyFor("FullName")]
    public string GivenName { get; set; }

    [AlsoNotifyFor("FullName")]
    public string FamilyName { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    public string FullName { get; set; }
}

DoNotNotifyAttribute

Use this attribute to exclude a property or type from having notification injected.

For Example

public class Person : INotifyPropertyChanged
{
    public string GivenName { get; set; }
    [DoNotNotify]
    public string FamilyName { get; set; }
    public event PropertyChangedEventHandler PropertyChanged;
}

DependsOnAttribute

Injects this property to be notified when a dependent property is set.

For Example

public class Person : INotifyPropertyChanged
{
    public string GivenName { get; set; }

    public string FamilyName { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    [DependsOn("GivenName","FamilyName")]
    public string FullName { get; set; }
}

DoNotSetChangedAttribute

Used to ignore IsChanged for a given property.

For Example below IsChanged will not be called when FullName is set.

public class Person: INotifyPropertyChanged
{
    [DoNotSetChanged]
    public string FullName { get; set; }
    public bool IsChanged { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
}

DoNotCheckEqualityAttribute

Used to skip equality check for a given property.

OnChangedMethodAttribute

Allows to specify the name of the method that will be called when the property changes.

    public class Person : INotifyPropertyChanged
    {
      public event PropertyChangedEventHandler PropertyChanged;

      [OnChangedMethod(nameof(OnMyNameChanged))]
      public string Name { get; set; }

      private void OnMyNameChanged()
      {
        Debug.WriteLine("Name changed");
      }
    }

SuppressPropertyChangedWarningsAttribute

Used to turn off build warnings about mismatched On_PropertyName_Changed methods.