Reputation: 342
I can't succeed to make the xct:TouchEffect.Command working on UWP while:
I made a very small project to test it:
Start a new Mobile APP project in VS2019
Add the Xamarin.CommunityToolKit
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++ );
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: Version of Xamarin 5.0.0.2012
Upvotes: 3
Views: 1585
Reputation: 342
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.
Upvotes: 2
Reputation: 32775
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.
Upvotes: 0
Reputation: 78
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++ );
Upvotes: 0