我有一个使用 MVVM 的 Xamarin Forms 项目,我在其中尝试使用 Fody 和 PropertyChanged.Fody 包。无论我尝试什么,它都不起作用。我花了一天时间搜索使用 PropertyChanged.Fody 的项目示例,但找不到任何实际工作的示例示例代码。有人可以帮我吗?谢谢。
我已将 Fody 和 PropertyChanged.Fody nugets 添加到项目中。
我已将 FodyWeavers.xml 文件添加到 Forms 项目中,看起来像......
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<PropertyChanged />
</Weavers>
我的观点是标准的 ContentPage ...
<ContentPage.BindingContext>
<viewmodels:GetStartedViewModel />
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout >
<Entry Text="{Binding TestMessage}" TextColor="Lime" FontSize="20" />
</StackLayout>
</ContentPage.Content>
我尝试以 2 种方式在 ViewModel 上实现 PropertyChanged.Fody,但这两种方式都不起作用。
1)
public class GetStartedViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string TestMessage { get; set; }
}
2)
[AddINotifyPropertyChangedInterface]
public class GetStartedViewModel
{
public string TestMessage { get; set; }
}