[BUG] mct:EventToCommandBehavior not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit
Is there an existing issue for this?
- [x] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
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
- Run your samples project from this GitHub repo - i added it below as well
- Click on the Flyout
- Select Behaviors
- 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
This may be related. I just updated to 10.0.0 and the first EventToCommandBehavior in my solution failed. No errors or messages, just stopped working. This is the code piece that stopped, when I rolled back to 9.1.1 it started working again.
<CollectionView.Behaviors>
<toolkit:EventToCommandBehavior
x:Name="CustomerSelectionBehavior"
Command="{Binding CustomerSelectedCommand}"
CommandParameter="{Binding SelectedItem, Source={x:Reference CustomerCollectionView}}"
EventName="SelectionChanged" />
</CollectionView.Behaviors>
@jamesingreersc Your issue is not related. Here's the relevant excerpt from the Release Notes to fix your issue:
@brminnick ahhh, release notes :) Thats what I get for updating all nugets at once without reading them. Just tested with the new BindingContext and it's working just fine.
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
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>
I'm getting thewsamw issue with "EnumToBoolConverter":
<ResourceDictionary>
<toolkit:EnumToBoolConverter x:Key="enumToBoolConverter" />
</ResourceDictionary>
{Microsoft.Maui.Controls.Xaml.XamlParseException: Position 15:14. Type toolkit:EnumToBoolConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit
at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Microsoft.Maui.Controls.Xaml.ListNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[LoginPage](LoginPage view, Type callingType)
at HostedTime_Maui.Views.LoginPage.InitializeComponent()
Any solution?
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
binandobjfolders:
<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.
<ItemGroup> <TrimmerRootAssembly Include="CommunityToolkit.Maui"/> </ItemGroup>
Adding this fixes the problem on ios, but now i get this when i try to build a release for android:
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/35.0.24/targets/Microsoft.Android.Sdk.ILLink.targets(104,5): error MSB4096: The item "CommunityToolkit.Maui" in item list "TrimmerRootAssembly" does not define a value for metadata "RootMode". In order to use this metadata, either qualify it by specifying %(TrimmerRootAssembly.RootMode), or ensure that all items in this list define a value for this metadata.
Got it, it has to be
<ItemGroup>
<TrimmerRootAssembly Include="CommunityToolkit.Maui" RootMode="All" />
</ItemGroup>
The worst change ever
Got it, it has to be
<ItemGroup> <TrimmerRootAssembly Include="CommunityToolkit.Maui" RootMode="All" /> </ItemGroup>
Thanks! It helped me
I am facing issue where the Appearing event wont be triggered for content page. It stopeed working after upgrading CommunityToolkit.Maui to 10.0.0
I am injecting binding context to constructor of page.
Page is simple:
<?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:Class="TB.DanceDance.Mobile.Pages.EventsPage">
<ContentPage.Behaviors>
<toolkit:EventToCommandBehavior
EventName="Appearing"
Command="{Binding AppearingCommand}" />
</ContentPage.Behaviors>
<Grid>
<Button Command="{Binding AddEventCommand}" Text="Add Event"></Button>
</Grid>
</ContentPage>
public partial class EventsPage : ContentPage
{
public EventsPage(EventsPageModel eventsPageModel)
{
BindingContext = eventsPageModel; // BindingContext is correct
InitializeComponent();
Debug.WriteLine("Test"); // I can see this in logs.
}
protected override void OnAppearing()
{
base.OnAppearing();
Debug.WriteLine("OnAppearingAA"); // I can see this in logs
}
}
public partial class EventsPageModel : ObservableObject
{
[RelayCommand]
private async Task Appearing()
{
Debug.WriteLine("Appearing Binded"); // works with CommunityToolkit.Maui v9.1.1 - Does not work with v10.0.0+
}
[RelayCommand]
private async Task AddEvent()
{
Debug.WriteLine("AddEvent"); // it works
}
Am I doing something wrong? From my understanding I don't have to set binding context in EventToCommandBehavior as it is set in constructor.
@possibility022 You do need to set the BindingContext on the behavior as documented in the release notes https://github.com/CommunityToolkit/Maui/releases/tag/10.0.0
@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:
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
}
}
I had this exact same issue, but with a converter. It would only crash on an iOS device, and only in builds that were published via TestFlight. It would not crash on an iOS device where the app was deployed via a debugger.
Due to logging, I was able to find out what the error was:
Microsoft.Maui.Controls.Xaml.XamlParseException: Position 20:10. Type toolkit:InvertedBoolConverter not found in xmlns http://schemas.microsoft.com/dotnet/2022/maui/toolkit
My apps target .NET 8 and use 9.1.1 of the MCT (latest version for .NET 8). This wasn't an issue using 9.0.x of MCT, but trimming support was added in the 9.1.x revision.
The TrimmerRootAssembly solution mentioned before solved the issue, but I just wanted to point out a key detail. I have multiple apps that all include the same class library (I'll refer to it as "Core").
Apps A, B and C all depend on Core, which has a lot of common XAML, views, models, and so on inside. Core depends on CommunityToolkit.Maui. It is important to put the TrimmerRootAssembly workaround in the .csproj for the apps, not in the Core .csproj.
If anyone else has a similar project setup, producing multiple apps, I thought I'd explain this important point, allowing you to keep whatever hair you have left! 🧑🦲
I believe this should be fixed through PR: https://github.com/CommunityToolkit/Maui/pull/2460
MainPage.xaml(22, 17): [XC0045] Binding: Property "BindingContext" not found on "MauiPlate.PageModels.MainPageModel".
@bijington感谢您的确认。
今天我花了更多时间来完成它并让它正常工作。 我发现以下两条评论很有帮助:
我的代码如下所示:
<?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 } }
MainPage.xaml(22, 17): [XC0045] Binding: Property "BindingContext" not found on "MauiPlate.PageModels.MainPageModel".
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
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
BindingContextto your page but setting theDataTypeto the view model. TheDataTypeneeds to be set to your page type so I matches the type being assigned toBindingContext
Could you provide an example of "needs to set to your page type" I have the sane problem but I cannot make it work
Ok I got it x:Datatype=ContentPage