admin管理员组文章数量:1295723
In a console project.
Program.cs
using ObservablePropertyTests;
NotifyOtherProperty notifyOtherProperty = new NotifyOtherProperty
{
Name = "Foo",
AnotherName = "2Foo",
};
notifyOtherProperty.Name = "Bar";
ObservablePropertyTest.cs
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}");
}
}
}
Output:
OnNameChanging
-> Foo
OnAnotherNameChanged
-> 2Foo
OnNameChanging
Foo -> Bar
Why isn't OnAnotherNameChanged called by the second assignment("Foo" to "Bar")?
.Net version: 8.0.404
Mvvm Toolkit version: 8.4.0
本文标签: Why NotifyPropertyChangedFor not working for OnAnotherNameChanged in C MVVM toolkitStack Overflow
版权声明:本文标题:Why NotifyPropertyChangedFor not working for OnAnotherNameChanged in C# MVVM toolkit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741622322a2388881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论