Warum notifyPropertychanged für nicht für Onanothernamechanged im C# MVVM -ToolkitC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Warum notifyPropertychanged für nicht für Onanothernamechanged im C# MVVM -Toolkit

Post by Anonymous »

In einem Konsolenprojekt.using ObservablePropertyTests;

NotifyOtherProperty notifyOtherProperty = new NotifyOtherProperty
{
Name = "Foo",
AnotherName = "2Foo",
};
notifyOtherProperty.Name = "Bar";
< /code>
ObservableProperty test.csp>
using CommunityToolkit.Mvvm.ComponentModel;

namespace ObservablePropertyTests
{
public partial class NotifyOtherProperty : ObservableObject
{
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(AnotherName))]
private string? name;

[ObservableProperty]
private string? anotherName;

partial void OnNameChanging(string? oldValue, string? newValue)
{
Console.WriteLine("OnNameChanging");
Console.WriteLine($"{oldValue} -> {newValue}");
}

partial void OnAnotherNameChanged(string? oldValue, string? newValue)
{
Console.WriteLine("OnAnotherNameChanged");
Console.WriteLine($"{oldValue} -> {newValue}");
}
}
}
< /code>
Ausgabe: < /p>
OnNameChanging
-> Foo
OnAnotherNameChanged
-> 2Foo
OnNameChanging
Foo -> Bar
< /code>
Warum wird Onanothernamechange nicht von der zweiten Zuordnung ("foo" zu "bar") angerufen? /p>
MVVM Toolkit -Version: 8.4.0 < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post