0

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}">
    ...
Sam Hood
  • 361
  • 3
  • 14

1 Answers1

1

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.

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • You are an absolute hero, I was pulling my hair out with this and that sorted it. Error no longer popping up! Thank you! (And thanks for that github link too, some handy info there) – Sam Hood Apr 13 '23 at 08:41