В консольном проекте. < /p>
program.cs
using ObservablePropertyTests;
NotifyOtherProperty notifyOtherProperty = new NotifyOtherProperty
{
Name = "Foo",
AnotherName = "2Foo",
};
notifyOtherProperty.Name = "Bar";
< /code>
test visembleproperty 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>
output: < /p>
OnNameChanging
-> Foo
OnAnotherNameChanged
-> 2Foo
OnNameChanging
Foo -> Bar
< /code>
Почему не называется вторым заданием («Foo» для «bar»)? /p>
mvvm toolkit версия: 8.4.0 < /p>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -sharp-mvv
Зачем уведомлять PropertyChanged для не работать на onanothernameChanged в C# MVVM Toolkit ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Почему Visual Studio не генерирует дополнительный код Community.Toolkit.MVVM автоматически?
Anonymous » » в форуме C# - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-