2

I can't succeed to make the xct:TouchEffect.Command working on UWP while:

  • it is working for android in the same project ...
  • there is no build error or warning

I made a very small project to test it:

  1. Start a new Mobile APP project in VS2019

  2. Add the Xamarin.CommunityToolKit

  3. Add two properties in the Mainpage.xaml.cs (ok, it could be better implemented but it works) :

     private int count = 10;
     public  int Count
     {
         get => count;
         set
         {
             count = value;
             OnPropertyChanged(nameof(Count));
         }
     }
    
     public ICommand PressedCommand => new Command ( () => Count++ );
    
  4. Update the MainPage.xaml like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="CommunityToolKit.MainPage"
             x:Name="this">

    <StackLayout>

        <Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
            <Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
        </Frame>
        <StackLayout BackgroundColor="IndianRed"
                     xct:TouchEffect.Command="{Binding Path=PressedCommand, Source={x:Reference this}}">
            <Label Text="Start developing now" FontSize="Title" Padding="30,10,30,10"/>
            <Label Text="Make changes to your XAML file and save" FontSize="16" Padding="30,0,30,0"/>
        </StackLayout>

        <Label Text="{Binding Path=Count, Source={x:Reference this}}" Padding="30" HorizontalOptions="Center"/>
        <Button Text="Click Me" Command="{Binding Path=PressedCommand, Source={x:Reference this}}"/>
    </StackLayout>

</ContentPage>

The binding for the command of the button is working on both UWP and Android projects. But the binding of the touchEffect applied on the StackLayout is not working on the UWP project (When I click on the IndianRed Background or wherever in the StackLayout).

What did I miss ?!? Any idea ?

EDIT:

I mention that I'm aware of this post: https://github.com/xamarin/XamarinCommunityToolkit/issues/1456

So my options are curently the folowing: enter image description here Version of Xamarin 5.0.0.2012

Belight
  • 205
  • 2
  • 14
  • That's strange, the same code works in official code sample [here](https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Effects/TouchEffectPage.xaml#L120). – Nico Zhu Aug 31 '21 at 08:13
  • 1
    Yes, it is strange and boring ... I made a GitHub repo with the project https://github.com/BelightWavre/CommunityToolKit – Belight Aug 31 '21 at 08:22
  • please rollback version 1.0 it could work as expect. please view the blow the answer – Nico Zhu Aug 31 '21 at 08:26
  • Have you tried that? does it work in your side with 1.0 version? – Nico Zhu Aug 31 '21 at 08:54

3 Answers3

1

Ok, I get the solution from AndreiMisiukevich on the Xamarin.CommunityToolKit project here

In order to let the ToolKit running in UWP release mode (it already works in debug mode by standard), I had to add those lines in file App.xaml.cs of the UWP project:

var assembliesToInclude = new List<Assembly>() { typeof(Xamarin.CommunityToolkit.Effects.TouchEffect).GetTypeInfo().Assembly };
Xamarin.Forms.Forms.Init(e, assembliesToInclude);

It works with release 1.2.0 of the CommunityToolKit and Xamarin 5.0.0.2083.

In fact, as I use Rg.Plugins.Popup, I transform those lines like this:

var assembliesToInclude = new List<Assembly>() { typeof(Xamarin.CommunityToolkit.Effects.TouchEffect).GetTypeInfo().Assembly };
assembliesToInclude.AddRange(Rg.Plugins.Popup.Popup.GetExtraAssemblies());
Xamarin.Forms.Forms.Init(e, assembliesToInclude);

Thanks everybody for the suggestions and AndreiMisiukevich for the solution.

Belight
  • 205
  • 2
  • 14
0

I think you would need a public getter and setter for command to work properly. That has been my experience till date. Try adding a public get in your command like this:

public ICommand PressedCommand { get; } => new Command ( () => Count++ );
  • I tried this : public ICommand PressedCommand { get => new Command(() => Count++); } but it don't change anything. – Belight Aug 31 '21 at 07:33
0

Xamarin.CommunityToolKit TouchEffect.Command not working in UWP

It's know issue for latest CommunityToolKit version, but it works well in earlier version.

Currently there is a workaround that rollback to Xamarin.CommunityToolKit version 1.0.0. And official code sample used version is 1.0.0.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Thx for the response, I downgrade the package to 1.0.0 but it doesn't work yet. I upgrade my sample on GitHub. It's so frustrating ... What did I miss ?!? – Belight Aug 31 '21 at 12:29
  • I never read something about this Xamarin.CommunityToolKit.Markup. What do you mean by adding "Xamarin.CommunityToolKit.Markup (1.0.0) page" ? I added the Nuget package on all the projects (UWP/Android). Then ? How to reference it ? – Belight Sep 01 '21 at 07:12
  • just add it for forms project. please refer this [document](https://github.com/xamarin/XamarinCommunityToolkit#installation) – Nico Zhu Sep 01 '21 at 07:21
  • 1
    Yesss, I found something, but not so good ... With the same project (and the Nuget package installed like discussed here), it works in debug mode but not in release mode. Seamingly no error triggered. Does it mean/reveale something for you ? – Belight Sep 01 '21 at 15:47