-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
area-xamlXAML, CSS, Triggers, BehaviorsXAML, CSS, Triggers, BehaviorsxsgXaml sourceGenXaml sourceGen
Description
The CommuityToolkit.Mvvm package has a source generator for generating relay commands like this:
[RelayCommand]
private async Task Save()
{
// ...
}will produce:
/// <summary>The backing field for <see cref="SaveCommand"/>.</summary>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.3.0.0")]
private global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand? saveCommand;
/// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand"/> instance wrapping <see cref="Save"/>.</summary>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.3.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand SaveCommand => saveCommand ??= new global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand(new global::System.Func<global::System.Threading.Tasks.Task>(Save));It is common to then bind this command to a button Click or any other event:
<Button Text="Save" Command="{Binding SaveCommand}" />Note: the attribute does not have any option to override the generated property name. The name is always $"{propertyName}Command".
Currently, the binding compiler will fail to compile, because the SaveCommand property is generated by another source generator which it cannot see. This is a limitation of both the BindingSourceGen and XAML SourceGen. The fix should be in shared code.
Copilot
Metadata
Metadata
Assignees
Labels
area-xamlXAML, CSS, Triggers, BehaviorsXAML, CSS, Triggers, BehaviorsxsgXaml sourceGenXaml sourceGen