`RaisePropertyChanged` method in `ObservableObject`

Offen
#1,086 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
csharp

Rechercherichtung

Finde die ObservableObject-Implementierung und die vorhandenen PropertyChanged-Tests oder Einstiegspunkte. Vergleiche das vorgeschlagene Verhalten von RaisePropertyChanged und OnPropertyChanged und verifiziere anschließend, dass der direkte Ereignisauslösungspfad funktioniert, ohne Überschreibungen aufzurufen, und dass die relevanten Tests erfolgreich sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature request :mailbox_with_mail:
Overview

Trying to replace an internal, legacy implementation of ObservableCollection with the one in CommunityToolkit it was noticed there is no way to simply raise the PropertyChanged event without invoking OnPropertyChanged and any overrides.

This functionality is relied upon in some cases and it's time consuming to work around. Since it seems harmless adding upstream here to ObservableObject I created this ticket.

API breakdown
class ObservableObject
{
    protected void RaisePropertyChanged([CallerMemberName] string? propertyName = null)
    {
        PropertyChanged?.Invoke(new PropertyChangedEventArgs(propertyName));
    }

    protected void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChanged?.Invoke(e);
    }
}
Usage example

The cases where this is most useful are those where you are doing something within an OnPropertyChanged override and want to raise some event manually (you just calculated something manually). If you use OnPropertyChanged again it's going to crash with a stack overflow as it keeps calling itself. Of course you can guard against this but it seems easy enough just to support the ability to raise the event directly. Tooling should generally let you do what you want to do while guiding towards a proper flow. Not restrict you completely.

Breaking change?

No

Alternatives

None in this context. Would just have to force all code to work with OnPropertyChanged only.

Additional context

No response

Help us help you

No, just wanted to propose this

Vorherrschende Sprache
C#
Sterne
3.8k
Forks
400
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus CommunityToolkit/dotnet

Alle Issues in CommunityToolkit/dotnet

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.