【发布时间】:2021-10-29 18:05:12
【问题描述】:
我无法成功使 xct:TouchEffect.Command 在 UWP 上运行,同时:
- 它在同一个项目中适用于 android ...
- 没有构建错误或警告
我做了一个很小的项目来测试它:
-
在VS2019中启动一个新的Mobile APP项目
-
添加 Xamarin.CommunityToolKit
-
在 Mainpage.xaml.cs 中添加两个属性(好的,它可以更好地实现但它可以工作):
private int count = 10; public int Count { get => count; set { count = value; OnPropertyChanged(nameof(Count)); } } public ICommand PressedCommand => new Command ( () => Count++ ); -
像这样更新 MainPage.xaml:
<?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>
按钮命令的绑定适用于 UWP 和 Android 项目。但是应用于 StackLayout 的 touchEffect 绑定在 UWP 项目上不起作用(当我单击 IndianRed 背景或 StackLayout 中的任何位置时)。
我错过了什么?!?有什么想法吗?
编辑:
我提到我知道这个帖子:https://github.com/xamarin/XamarinCommunityToolkit/issues/1456
【问题讨论】:
-
奇怪了,官方代码样例here也是一样的代码。
-
是的,这很奇怪很无聊......我用项目github.com/BelightWavre/CommunityToolKit做了一个GitHub repo
-
请回滚 1.0 版,它可以按预期工作。请查看打击答案
-
你试过了吗? 1.0版本对你有用吗?
标签: c# xamarin.forms uwp command windows-community-toolkit