| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The DevExpress MVVM Framework includes a source generator that produces boilerplate code for your View Models at compile time. You need to define a stub View Model class that specifies the required logic. Our MVVM Framework analyzes your implementation and applied attributes to generate the final View Model class with all required boilerplate code.
Generator.mp4Base View Model
Create a partial class. Add attributes to the class and its fields/methods:
using DevExpress.Mvvm.CodeGenerators;
[GenerateViewModel]
partial class ViewModel {
[GenerateProperty]
string username;
[GenerateProperty]
string status;
[GenerateCommand]
void Login() => Status = "User: " + Username;
bool CanLogin() => !string.IsNullOrEmpty(Username);
}Generated View Model
The generator inspects the base View Model and produces a partial class that complements your implementation with the following boilerplate code:
You can view and debug the generated View Model:
partial class ViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler? PropertyChanged;
protected void RaisePropertyChanged(PropertyChangedEventArgs e) => PropertyChanged?.Invoke(this, e);
public string? Username {
get => username;
set {
if(EqualityComparer<string?>.Default.Equals(username, value)) return;
username = value;
RaisePropertyChanged(UsernameChangedEventArgs);
}
}
public string? Status {
get => status;
set {
if(EqualityComparer<string?>.Default.Equals(status, value)) return;
status = value;
RaisePropertyChanged(StatusChangedEventArgs);
}
}
DelegateCommand? loginCommand;
public DelegateCommand LoginCommand {
get => loginCommand ??= new DelegateCommand(Login, CanLogin, true);
}
static PropertyChangedEventArgs UsernameChangedEventArgs = new PropertyChangedEventArgs(nameof(Username));
static PropertyChangedEventArgs StatusChangedEventArgs = new PropertyChangedEventArgs(nameof(Status));
}Your project should meet the following requirements:
Prepare your project as outlined below to enable support for View Models generated at compile time:
Add a reference to the DevExpress.Mvvm.v21.1+ or install the DevExpress.Mvvm NuGet package.
Install the DevExpress.Mvvm.CodeGenerators NuGet package in your project.
Set the language version to 9 in the .csproject file:
<PropertyGroup>
<LangVersion>9</LangVersion>
</PropertyGroup>For .NET Core projects, set the IncludePackageReferencesDuringMarkupCompilation property to true additionally:
<PropertyGroup>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>Updates for the DevExpress.Mvvm.CodeGenerators NuGet package are released independently of the DevExpress component suite release cycle. We do not set specific release dates; we publish a new version when we fix reported issues.
The version number for the DevExpress.Mvvm.CodeGenerators package does not need to match that of DevExpress components. The latest available versions are compatible.
Our View Model Code Generator now supports the Prism Library.
We fixed the following issue: A sealed class generates protected methods.
If you use a sealed class, the following members of the generated View Model class will have the private access modifier:
| Back | FazBrowse Home | New Git URL |