单击后如何在StackLayout或Grid中实现平滑的背景色变化效果?如果我们创建一个按钮,则它具有开箱即用的效果-我在随附的gif中进行了显示。 ListView中的ViewCell也是如此。单击后还具有改变背景颜色的波纹效果。但是如何为StackLayout或Grid实现呢?
如何实现
答案 0 :(得分:1)
解决方案1:
您认为ViewCell具有单击后更改背景颜色的波纹效果。您可以将 Stacklayout 或 Grid 放入只有一个ViewCell的列表视图中。
在xaml中
<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;
}
}
解决方案2:
您可以使用来自nuget的软件包TouchView
将nuget包添加到Xamarin.Forms .netStandard / PCL项目以及特定于平台的项目(iOS和Android)中
iOS:将TouchViewRenderer.Initialize()行添加到您的AppDelegate (从链接器保留)
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);
}
}
}
在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: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
}
答案 1 :(得分:1)
if (dest <= src) {
/* do the above */
} else {
int i = (int)strlen(src);
while (i >= 0) {
dst[i] = src[i];
i--;
}
}