Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The C# language version must be set to 'preview' when using [ObservableProperty]
on partial properties for the source generators to emit valid code.
This is required because the generated code for [ObservableProperty]
on partial properties uses some preview features. Make sure to add <LangVersion>preview</LangVersion>
(or above) to your .csproj file.
To learn more about how to enable a newer C# version on older frameworks, see this blog post.
The following sample generates MVVMTK0041:
<PropertyGroup>
<LangVersion>13.0</LangVersion>
</PropertyGroup>
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp;
public partial class SampleViewModel : ObservableObject
{
[ObservableProperty]
public partial string? Name { get; set; }
}
Additional resources
- You can find more examples in the unit tests.
MVVM Toolkit