Skip to content

MAUIG2045 false warning when binding to CommunityToolkit.Mvvm [RelayCommand] generated commands #34086

@eduardoagr

Description

@eduardoagr

When using CommunityToolkit.Mvvm with [RelayCommand], MAUI’s XAML compiler (XamlC) cannot see the generated command property during compile time. This results in a false MAUIG2045 warning:
Binding: Property "ColorChangedCommand" not found on "MainPageViewModel".
The binding will use slower reflection-based binding at runtime.
If this property is generated by another source generator, consider reporting this..

Binding: Property "ColorChangedCommand" not found on "MainPageViewModel". The binding will use slower reflection-based binding at runtime. If this property is generated by another source generator, consider reporting this...

However, the property does exist at runtime:

[RelayCommand]
public void OnColorChanged(Color newColor) { ... }
// Generates: public IRelayCommand ColorChangedCommand { get; }

But MAUI compiled bindings cannot see the generated property, causing the warning.
Expected behavior:
MAUI’s XAML compiler should recognize properties generated by other source generators (especially CommunityToolkit.Mvvm, which is widely used).
Actual behavior:
MAUI emits MAUIG2045 even though the property exists and works at runtime.
Repro steps:

  • Create a ViewModel using CommunityToolkit.Mvvm
  • Add a [RelayCommand] method:
    [RelayCommand]
    public void OnColorChanged(Color c) { }
  • Bind to the generated command in XAML:
    ColorChangedCommand="{x:Binding ColorChangedCommand}"
  • Add x:DataType="YourViewModel" to enable compiled bindings
  • Build → MAUIG2045 warning appears
    Environment:
  • .NET MAUI 10
  • CommunityToolkit.Mvvm 8+
  • Windows / Android / iOS
  • Visual Studio 2022
    Notes:
    This appears to be a source generator ordering / visibility issue.
    MAUI XamlC runs before the Toolkit generator, so it cannot see the generated members.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions