Animation Xamarin表单中的动画和网格长度

Animation Xamarin表单中的动画和网格长度,animation,xamarin.forms,gridlength,Animation,Xamarin.forms,Gridlength,我有班级模型 public class Model : INotifyPropertyChanged ... private GridLength detailsPanelHeight { get; set; } public GridLength DetailsPanelHeight { get { return detailsPanelHeight; } set { if (!GridLength.Equals(detailsPanelHeight,

我有班级模型

public class Model : INotifyPropertyChanged
...
private GridLength detailsPanelHeight { get; set; }
public GridLength DetailsPanelHeight
{
    get { return detailsPanelHeight; }
    set
    {
        if (!GridLength.Equals(detailsPanelHeight, value))
        {
            detailsPanelHeight = value;
            OnPropertyChanged("DetailsPanelHeight");
        }
    }
}
...
XAML代码的一部分:

执行动画的代码(平滑更改行高度):

折叠行的代码:
var animate=新动画(d=>currentItem.DetailsPanelHeight=d,100,0);
制作动画。提交(这是“CollapseAnimation”,501000,Easing.SpringOut)

它第一次起作用,但第二次出现错误:“值小于0或不是数字\n参数名称:值”。我看到
d
值小于零


我能做些什么来解决这个问题呢?

我用过这样的东西,它对我非常有效。我希望它也适合你

此动画在调用删除操作后调用命令时折叠视图单元格。代码如下:

tap事件处理程序: 动画方法 转换回调函数
我希望它对你有用。

@Diego,没用。我使用0.001代替0:
var animate=new Animation(d=>currentItem.DetailsPanelHeight=d,100,0.001)可能问题在于double和GridLength之间的转换。可能吗?
var animate = new Animation(d => currentItem.DetailsPanelHeight = d, 0, 100);
animate.Commit(this, "ExpandAnimation", 50, 1000, Easing.SpringOut);
private async void RemoveButtonTapped(object sender, EventArgs e)
{
    Parallel.Invoke(() =>
        {
             if (RemoveCommand?.CanExecute(RemoveCommandParameter) ?? false)
                 RemoveCommand.Execute(RemoveCommandParameter);
        },
        AnimatedDestruction);
}
private async void AnimatedDestruction()
{
    uint transitionTime = 300;
    decimal delayFactor = 1.2m;

    // Note: stackPanel is the viewCell's top-level container

    await Task.WhenAll(
        stackPanel.FadeTo(0, Convert.ToUInt32(transitionTime * delayFactor), Easing.CubicInOut),
        View.InterpolateValue(stackPanel.Height, 0, Transition, transitionTime, Easing.CubicInOut)
        );
}
private void Transition(double value)
{
    const double minHeightValue = 0.001;

    value = value <= minHeightValue ? minHeightValue : value;

    Height = value;
    ForceUpdateSize();
}   
public static Task<bool> InterpolateValue(this View view, double initialValue, double endValue, Action<double> transformIteration, uint length, Easing easing)
{
    Task<bool> ret = new Task<bool>(() => false);

    if (!view.AnimationIsRunning(nameof(InterpolateValue)))
    {
        try
        {
            easing = easing ?? Easing.Linear;
            var taskCompletionSource = new TaskCompletionSource<bool>();

            view.Animate(nameof(InterpolateValue), ((_double) => initialValue - (initialValue * _double)), transformIteration, 16, length, easing, (v, c) => taskCompletionSource.SetResult(c));
            ret = taskCompletionSource.Task;
        }
        catch
        {
            // supress animation overlapping errors 
        }
    }

    return ret;
}