Skip to content

WPF0005 false positive #262

Open
Open
@brian-reichle

Description

@brian-reichle

I'm getting a WPF0005 false positive using WpfAnalyzers 2.4.0.

class Selectable : Control
{
    public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
        nameof(IsSelected),
        typeof(bool),
        typeof(Selectable),
        new PropertyMetadata(new PropertyChangedCallback(OnIsSelectedChanged)));

    public bool IsSelected
    {
        get => (bool)GetValue(IsSelectedProperty);
        set => SetValue(IsSelectedProperty, value);
    }

    static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = (Selectable)d;

        if ((bool)e.NewValue)
        {
            control.OnSelected();
        }
        else
        {
            control.OnUnseected();
        }
    }

    protected virtual void OnUnseected() // <-- WPF0005: Method 'OnUnselected' should be named 'OnIsSelectedChanged'
    {
    }

    protected virtual void OnSelected() // <-- WPF0005: Method 'OnSelected' should be named 'OnIsSelectedChanged'
    {
    }
}

Extracting 'if' block to another method seems to resolve the issue, so I'm not particularly concerned by it, just thought I should raise the issue in case you wanted to do something about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions