Search code examples
xamarinmauixamarin-community-toolkit

Type TouchEffect not found in xmlns with Xamarin.CommunityToolkit.MauiCompat


I'm trying to get a long press touch effect working with MAUI; through various threads on this I've ended up using the Xamarin.CommunityToolkit.MauiCompat package to allow me to use the TouchEffect that's not in MAUI yet.

The issue I'm having is when I run this, an exception is thrown on the InitializeComponent call - Microsoft.Maui.Controls.Xaml.XamlParseException: 'Position 10:36. Type TouchEffect not found in xmlns http://xamarin.com/schemas/2020/toolkit'

The weird thing is that Intellisense knows that TouchEffect is there, when I start typing xct: it suggests everything that I would expect to be available, so it's almost like it's a runtime linking issue or something. I can't for the life of me figure out what's going wrong and Google searches have been unfruitful.

Here's my page's XML:

<?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:xct="http://xamarin.com/schemas/2020/toolkit"
         x:Name="ArtistsPage"
         x:Class="MediaServerApp.Artists"
         xmlns:controls="clr-namespace:MediaServerApp"
         NavigationPage.HasNavigationBar="False"
         Title="" >
    <FlexLayout Direction="Column" xct:TouchEffect.Command="{Binding LongPressItem}">
    ...

Solution

  • You can change the xmlns:xct="http://xamarin.com/schemas/2020/toolkit" to xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.Effects;assembly=Xamarin.CommunityToolkit.MauiCompat". Such as:

    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.Effects;assembly=Xamarin.CommunityToolkit.MauiCompat"
             x:Name="ArtistsPage"
             x:Class="MediaServerApp.Artists"
             xmlns:controls="clr-namespace:MediaServerApp"
             NavigationPage.HasNavigationBar="False"
             Title="" >
        <FlexLayout Direction="Column" xct:TouchEffect.Command="{Binding LongPressItem}">
        ...
    

    I have tested this, and the project can deploy successfully. In addition, there is a bug about [MauiCompat] TouchEffect not working, you can refer to the workaround in it or follow up this issue.