Maui: [BUG] mct:EventToCommandBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the “Reporting a bug” section on Contributing file?

Current Behavior

I am using your Samples project from this GitHub repo because I was having issues with every version of MauiComminutyToolkit since 9.0.3

When I run your sample project i get the following error when I click on any of the following Behaviors. I did not test them all. But these are not working.

Position 25:18. Type mct:EventToCommandBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit

AnimationBehavior EventToCommandBehavior MaskedBehavior

In my personal project I’m getting the following error

Type toolkit:StatusBarBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit Type toolkit:TextCaseConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit Type toolkit:InvertedBoolConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit Type toolkit:EventToCommandBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit Type toolkit:IntToBoolConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit Type toolkit:IconTintColorBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit

here is my global.json file

{ “sdk”: { “version”: “9.0.101”, “rollForward”: “latestFeature”, “allowPrerelease”: false } }

Expected Behavior

I would expect the behaviors and converters to reference correctly.

Steps To Reproduce

  1. Run your samples project from this GitHub repo - i added it below as well
  2. Click on the Flyout
  3. Select Behaviors
  4. Click EventToCommandBehavior

Link to public reproduction project repository

https://github.com/jamesv-7/CommunityToolkit-10.0-Issues

Environment

- .NET MAUI CommunityToolkit:
- OS: MAC Sequoia 15.1
- .NET MAUI: 9.0
- XCode 16.1

Anything else?

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 20 (3 by maintainers)

Most upvoted comments

Got it, it has to be

	<ItemGroup>
		<TrimmerRootAssembly Include="CommunityToolkit.Maui" RootMode="All" />
	</ItemGroup>

@jamesingreersc Your issue is not related. Here’s the relevant excerpt from the Release Notes to fix your issue: Image

Do i also have to set the binding context for converters? Or is the breaking change only for behaviors? The release notes only mention behaviors, but i get the error Type toolkit:IsNotNullConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit

@brminnick We’re having the same problem here with .NET 8.0.404 with all the MCT converters in debug builds on MacOS, but absolutely fine on Windows. Seems to build fine for MacOS on DevOps in Release with the same SDK and workloads.

EDIT: This is with latest 9.x MCT for .NET 8

EDIT2: Seems to be related to linking - if set to ‘Link Framework SDKs Only’, as our debug project is, we get this error. Disabling linking makes MCT work, but then breaks other stuff in the build. Possibly something changed in the SDK? We were previously using 8.0.101 on MacOS 14.x where this worked, but with 8.0.404 on MacOS 15.x it now fails.

EDIT3: Excluding MCT from trimming resolves the issue (FYI @gmwilhelm & @jamesv-7) - add the following to your csproj then make sure to clear your bin and obj folders:

<ItemGroup> <TrimmerRootAssembly Include="CommunityToolkit.Maui"/> </ItemGroup> > ```
<ItemGroup>
    <TrimmerRootAssembly Include="CommunityToolkit.Maui"/>
</ItemGroup>

This actually fixed the issue. Thanks. I’m hoping this is not a band-aide to a much bigger problem in the future. I hope the dev can look into it.

Do i also have to set the binding context for converters? Or is the breaking change only for behaviors?

The release notes only mention behaviors, but i get the error

Type toolkit:IsNotNullConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit

@brminnick We’re having the same problem here with .NET 8.0.404 with all the MCT converters in debug builds on MacOS, but absolutely fine on Windows. Seems to build fine for MacOS on DevOps in Release with the same SDK and workloads.

EDIT: This is with latest 9.x MCT for .NET 8

EDIT2: Seems to be related to linking - if set to ‘Link Framework SDKs Only’, as our debug project is, we get this error. Disabling linking makes MCT work, but then breaks other stuff in the build. Possibly something changed in the SDK? We were previously using 8.0.101 on MacOS 14.x where this worked, but with 8.0.404 on MacOS 15.x it now fails.

EDIT3: Excluding MCT from trimming resolves the issue (FYI @gmwilhelm & @jamesv-7) - add the following to your csproj then make sure to clear your bin and obj folders:

<ItemGroup>
    <TrimmerRootAssembly Include="CommunityToolkit.Maui"/>
</ItemGroup>

You have a mismatch between types:

<toolkit:EventToCommandBehavior 
            EventName="Appearing" BindingContext="{Binding Path=BindingContext, 
        Source={x:Reference EventsPageView}, 
        x:DataType=pageModels:EventsPageModel}"

Currently you are setting the behaviors BindingContext to your page but setting the DataType to the view model. The DataType needs to be set to your page type so I matches the type being assigned to BindingContext

@bijington Thank you for your confirmation.

I was able to spent more time on it today and got it working. I found these two comments helpful:

Github thread

Redit

My code looks like that:

<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:models="clr-namespace:TB.DanceDance.Mobile.Models"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" 
             xmlns:pageModels="clr-namespace:TB.DanceDance.Mobile.PageModels"
             x:DataType="pageModels:EventsPageModel"
             x:Name="EventsPageView"
             x:Class="TB.DanceDance.Mobile.Pages.EventsPage">
    <ContentPage.Behaviors>
        <toolkit:EventToCommandBehavior 
            EventName="Appearing" BindingContext="{Binding Path=BindingContext, 
        Source={x:Reference EventsPageView}, 
        x:DataType=pageModels:EventsPageModel}" 
            Command="{Binding AppearingCommand}"></toolkit:EventToCommandBehavior>
    </ContentPage.Behaviors>
        <Grid>
            <Button Command="{Binding AddEventCommand}" Text="Add Event"></Button>
        </Grid>
</ContentPage>
public partial class EventsPage : ContentPage
{
    public EventsPage(EventsPageModel eventsPageModel)
    {
        BindingContext = eventsPageModel;
        InitializeComponent();
        Debug.WriteLine("Test");
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        Debug.WriteLine("OnAppearingAA");
    }
}
public partial class EventsPageModel : ObservableObject
{
    [RelayCommand]
    private async Task Appearing()
    {
        Debug.WriteLine("Appearing Binded");
    }

    [RelayCommand]
    private async Task AddEvent()
    {
        Debug.WriteLine("AddEvent"); // it works
    }
}