You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] RelayCommand Source Generator Fails Silently for Methods Starting With ‘On' #1215
The name of the generated command will be created based on the method name. The generator will use the method name and append "Command" at the end, and it will strip the "On" prefix, if present. Additionally, for asynchronous methods, the "Async" suffix is also stripped before "Command" is appeneded.
However, the actual behaviour I am experiencing contradicts this claim.
Regression
No response
Steps to reproduce
Prerequisites:
.NET 10
C# 13
Create a new Avalonia (Ver. 12.1.3) desktop project. Your project file should include:
Add the CommunityToolkit.Mvvm (Ver. 8.4.2) NuGet package.
Create a ViewModel with [RelayCommand] methods starting with On.
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Diagnostics;
namespace MyTestApp.Avalonia.ViewModels;
public partial class TestViewModel : ObservableObject
(etc.)
[RelayCommand]
private void OnPointerPressed()
{
Debug.WriteLine("Pointer pressed.");
}
[RelayCommand]
private void AsdfPointerPressed()
{
Debug.WriteLine("Pointer pressed.");
}
Create a TestView. Attempt to bind to OnPointerPressedCommand.
<Window
x:Class="MyTestApp.Avalonia.Views.TestView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyTestApp.Avalonia.ViewModels"
Name="TestView"
x:DataType="vm:TestViewModel">
<!-- This binding will fail to compile. -->
<Button Command="{Binding OnPointerPressedCommand}" />
<!-- This binding will compile successfully. -->
<Button Command="{Binding AsdfPointerPressedCommand}" />
</Window>
Expected behavior
In the ViewModel, [RelayCommand] private void OnPointerPressed() { } would generate a PointerPressedCommand property, which the View could then execute.
For your OnPointerPressed() method, the generated property is PointerPressedCommand, matching the expected behavior you described. The binding should therefore be:
The method itself can stay named OnPointerPressed. AsdfPointerPressed() keeps its prefix and generates AsdfPointerPressedCommand.
I checked this with a complete compiled-XAML example using the same Toolkit 8.4.2, .NET 10 and C# 13, with Avalonia 12.1.4. The original binding fails compilation with AVLN2000 for the missing member; the corrected binding builds, and actual Avalonia headless pointer clicks execute the command and update the displayed count from 0 to 1 to 2. Replacing the DataContext and clicking again also works.
That is scripted headless validation on macOS, not a Windows run of your application. Your report uses Avalonia 12.1.3, so please check the corrected property name there first. If it still fails, the build diagnostic and generated members would help distinguish a separate problem from this binding-name mismatch.
I revisited my instructions. I can confirm that binding to PointerPressedCommand is now successful. For some reason, I was trying to bind to OnPointerPressedCommand.
Activity
tevinch commentedon Oct 24, 2026
The XAML in step 4 still includes the
Onprefix:For your
OnPointerPressed()method, the generated property isPointerPressedCommand, matching the expected behavior you described. The binding should therefore be:The method itself can stay named
OnPointerPressed.AsdfPointerPressed()keeps its prefix and generatesAsdfPointerPressedCommand.I checked this with a complete compiled-XAML example using the same Toolkit 8.4.2, .NET 10 and C# 13, with Avalonia 12.1.4. The original binding fails compilation with
AVLN2000for the missing member; the corrected binding builds, and actual Avalonia headless pointer clicks execute the command and update the displayed count from 0 to 1 to 2. Replacing the DataContext and clicking again also works.That is scripted headless validation on macOS, not a Windows run of your application. Your report uses Avalonia 12.1.3, so please check the corrected property name there first. If it still fails, the build diagnostic and generated members would help distinguish a separate problem from this binding-name mismatch.
JosiahDanger commentedon Oct 24, 2026
To @tevinch,
Thank you for your response and investigation.
I'm very sorry. I misunderstood the documentation.
I revisited my instructions. I can confirm that binding to
PointerPressedCommandis now successful. For some reason, I was trying to bind toOnPointerPressedCommand.You may close this Issue.