Does the MAUI UI Toolkit work with the MAUI MVVM Community toolkit?

1 Answer 89 Views
ListPicker
Mark
Top achievements
Rank 3
Iron
Iron
Iron
Mark asked on 20 Apr 2023, 10:18 AM | edited on 20 Apr 2023, 10:19 AM

Does the MAUI UI Toolkit work with the MAUI MVVM Community toolkit (), specifically the RelayCommand.

I am trying to configure the ListPicker to work with a RelayCommand but its not firing.

I am using the ListPicker on Windows, Latest Visual Studio, .net and Telerik versions.

XAML

<telerik:RadListPicker x:Name="WorkflowPicker" Placeholder="Select Workfow" ItemsSource="{Binding Workflows, Mode=TwoWay}" DisplayMemberPath="Name" PickerMode="DropDown" IsLooping="False" WidthRequest="300" Margin="3" BackgroundColor="Transparent" SelectedItem="{Binding SelectedWorkflow}">
                <telerik:RadListPicker.DropDownSettings>
                    <telerik:PickerDropDownSettings AcceptCommand="{Binding OnWorkflowsPickerAcceptRelay}" CancelCommand="{Binding WorkflowsPickerCancelCommand}" />
                </telerik:RadListPicker.DropDownSettings>
                <telerik:RadListPicker.ItemTemplate>
                    <DataTemplate>
                        <Label Text="{Binding Name}" HorizontalTextAlignment="Start" VerticalTextAlignment="Center"/>
                    </DataTemplate>
                </telerik:RadListPicker.ItemTemplate>
            </telerik:RadListPicker>

Page Model

public ICommand WorkflowsPickerCancelCommand { private set; get; }

public MainPageViewModel()
{
    this.WorkflowsPickerCancelCommand = new Command(this.OnWorkflowsPickerCancel);        
}

private void OnWorkflowsPickerCancel(object obj)
{
    // This fires        
}

[RelayCommand]
private void OnWorkflowsPickerAcceptRelay(object obj)
{
    // This does not fire
}

Are there any examples using the MVVM toolkit?

1 Answer, 1 is accepted

Sort by
1
Accepted
Lance | Senior Manager Technical Support
Telerik team
answered on 21 Apr 2023, 06:25 PM

Hello Mark,

We do not explicitly state any guaranteed compatibility with the various community toolkits. However, as long as they're using the standard MVVM interfaces and not custom types (e.g. ICommand), then it should work as-is.

Microsoft Guidance

According to the Microsoft documentation, they modify the name of the public command that is created by the source generators. Please see the "How It Works" section from the code-generators documentation => https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/relaycommand#how-it-works.

For your convenience, I'll paste the relevant text (underlines are my emphasis):

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.

Problem Identified

With that information, we now understand why your code is not working... the generated property name of the OnWorkflowsPickerAcceptRelay method would be "WorkflowsPickerAcceptRelayCommand",

In your XAML, you're attempting to bind to the name of the private method, not the generated property. this is why you're not seeing the method executing.


Pro Tip - You can always test any assumptions by using a standard MAUI Button, bind your expected source generator output to the Button command. You would have caught this much sooner because it wouldn't work for the button either.

Demo

Although debugging community toolkit code is outside the scope of the Telerik controls, I have gone ahead and created an app (attached) for you to confirm my theory is correct.

.

I hope this helps demystify how the toolkit's source generators work for commands.

Regards,
Lance | Manager Technical Support
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mark
Top achievements
Rank 3
Iron
Iron
Iron
commented on 24 Apr 2023, 09:32 AM

Hi, Thank you, this level of support is really appreciated. 👍
Tags
ListPicker
Asked by
Mark
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Lance | Senior Manager Technical Support
Telerik team
Share this question
or