Closed SamuelJames101 closed 1 year ago
There isn't really anything that looks wrong in that viewmodel, and I'm not familiar with the MAUI syntax at all. It's not clear at all that there's any problem with the MVVM Toolkit here, unless proven otherwise. This should be in the MAUI repo 🙂
I will close this, but feel free to share a minimal repro and I can reopen this. Until then, this seems more likely to either be some bug in the XAML code there, or some bug in MAUI. That viewmodel just seems completely fine to me.
@Sergio0694 If I bind to a normal Microsoft.maui.controls.command it works. It also isn't just me : https://stackoverflow.com/questions/76681900/binding-contextactions-menuitem-with-communitytoolkit-mvvm-in-maui.
I have been told to raise this issue in the Dotnet side apposed to the maui side which I originally raised it. https://github.com/CommunityToolkit/Maui/issues/1435
Can you reproduce the same issue if you manually declare the command? Ie. not using [RelayCommand]
, but rather defining a command property yourself and having it return the appropriate RelayCommand
instance. Does that work? 🤔
@Sergio0694 Is this what you mean?
public MainPageViewModel()
{
this.MyNormalCommand = new Command<string>(this.MyMenuItemMethodParameter);
}
public Command MyNormalCommand { get; set; }
Then in XAML
Command="{Binding BindingContext.MyNormalCommand, Source={x:Reference Name=test}}" CommandParameter="{Binding .}"
This is how I would do it if I was not using communitytoolkit.mvvm and this works
Yes, but use the RelayCommand<T>
type from the MVVM Toolkit.
@Sergio0694 The below results in the same as the first list in the screenshot
public MainPageViewModel()
{
this.MyNormalCommand = new RelayCommand<string>(this.MyMenuItemMethodParameter);
}
public RelayCommand<string> MyNormalCommand { get; set; }
Removing < string > gives the same result as the second list in the screenshot
public MainPageViewModel()
{
this.MyNormalCommand = new RelayCommand(this.MyMenuItemMethod);
}
public RelayCommand MyNormalCommand { get; set; }
Describe the bug
I have created a ListView. Created context actions. If a menu item in the context action points to a [RelayCommand] which takes a parameter then the list view items don't show.
Take away the parameter and it works.
Repo : https://github.com/SamuelJames101/comtoolkitIssueMaui
Steps to reproduce
Expected behavior
A ListView item pointer to a RelayCommand should show with or without a paramater.
Screenshots
IDE and version
VS 2022 Preview
IDE version
17.8.0 Preview 1.0
Nuget packages
Nuget package version(s)
8.2.1
Help us help you
No, just wanted to report this