Xamarin.forms 单击后StackLayout或Grid中的涟漪效应

Xamarin.forms 单击后StackLayout或Grid中的涟漪效应,xamarin.forms,grid,effect,ripple,stacklayout,Xamarin.forms,Grid,Effect,Ripple,Stacklayout,如何在单击后在StackLayout或Grid中实现背景色平滑变化的效果?如果我们创建一个按钮,它具有这种开箱即用的效果——我在附加的gif中显示了这一点。ListView中的ViewCell也是如此。它还具有点击后改变背景颜色的涟漪效应。但是,对于StackLayout或Grid,如何实现这一点呢 如何实现此目标解决方案1: 您说过ViewCell具有单击后更改背景颜色的涟漪效应。您可以将堆栈布局或网格放在只有一个ViewCell的listview中 在xaml中 在xaml中 BotonRe

如何在单击后在StackLayout或Grid中实现背景色平滑变化的效果?如果我们创建一个按钮,它具有这种开箱即用的效果——我在附加的gif中显示了这一点。ListView中的ViewCell也是如此。它还具有点击后改变背景颜色的涟漪效应。但是,对于StackLayout或Grid,如何实现这一点呢


如何实现此目标解决方案1:

您说过ViewCell具有单击后更改背景颜色的涟漪效应。您可以将堆栈布局网格放在只有一个ViewCell的listview中

在xaml中

在xaml中

BotonRefrescar.BackgroundColor=Color.FromHex(“#32CEF9”);
Device.StartTimer(时间跨度从毫秒(200),()=>
{
//做点什么
BotonRefrescar.BackgroundColor=Color.FromHex(“#32BBF9”);
返回false;
}
);
<StackLayout>


    <ListView x:Name="listView">

        <ListView.ItemTemplate>

            <DataTemplate>

                <ViewCell>

                    <StackLayout>

                      <Label TextColor="Black" Text="{Binding Content}"/>

                    </StackLayout>

                </ViewCell>

            </DataTemplate>

        </ListView.ItemTemplate>

    </ListView>

</StackLayout>
public class Data
{
    public string Content { get; set; }
}


public partial class MainPage : ContentPage
{

    public ObservableCollection<Data> MySource { get; set; }

    public MainPage()
    {
        InitializeComponent();

        BindingContext = this;



        MySource = new ObservableCollection<Data>()
        {
          new Data() {Content="Click Me" },
        };

        listView.ItemsSource = MySource;

    }

}
using TouchEffect.iOS;
namespace YourApp.iOS
{
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            TouchViewRenderer.Initialize();
            LoadApplication(new App());
            return base.FinishedLaunching(app, options);
        }
    }
}
<?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:local="clr-namespace:YourApp"
             xmlns:touch="clr-namespace:TouchEffect;assembly=TouchEffect"
             x:Class="App11.MainPage">

    <StackLayout>
        <touch:TouchView
            RegularBackgroundColor="LightGray"
            PressedBackgroundColor="Gray"
            PressedOpacity="1"       

            PressedAnimationDuration="100"
            RegularAnimationDuration="100"
            Padding="10, 5"
            VerticalOptions="CenterAndExpand"
            HorizontalOptions="CenterAndExpand"
            Completed="Handle_TouchCompleted"
           >

            <Label Text="Click Me" 
                   TextColor="Black" 
                   FontSize="30"/>

        </touch:TouchView>
    </StackLayout>

</ContentPage>
private void Handle_TouchCompleted(TouchEffect.TouchView sender, TouchEffect.EventArgs.TouchCompletedEventArgs args)
 {
    // do something you want        
 }