dotnet
dotnet copied to clipboard
RelayCommand attribute only works in .Net 6 and above?
Describe the bug
WPF, Using the [RelayCommand] in versions lower than .Net6 (.Net 5, .Net core3.1 etc.) will not prompt for the need to set partial for the class, and cause binding error at runtime:
System.Windows.Data Error: 40 : BindingExpression path error: 'ButtonClickCommand' property not found on 'object' ''ViewModel' (HashCode=47044325)'. BindingExpression:Path=ButtonClickCommand; DataItem='ViewModel' (HashCode=47044325); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
Regression
No response
Steps to reproduce
- ViewModel
public partial class ViewModel
{
[RelayCommand]
public void ButtonClick(object param)
{
Console.WriteLine(param);
}
}
- MainWindow.xaml.cs
public MainWindow()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
- MainWindow.xaml
<Grid>
<Button Command="{Binding ButtonClickCommand}"/>
</Grid>
Expected behavior
Support lower Net Version
Screenshots
No response
IDE and version
VS 2019
IDE version
No response
Nuget packages
- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.2.2
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item