我已经实现了一个自定义的AccordionControl。 它交替地由HeaderView和StackLayout组成。
当点击HeaderView时,使用动画展开相应的StackLayout。
对于动画,我需要一个起点和一个终点(渲染高度)。我目前已经实现了一种解决方法,它会很快显示StackLayout,获取渲染高度,然后对其进行动画处理。 (结果显然是一个不太流畅的动画)
动画-解决方法
stackLayout.IsVisible = true;
double heightWhenRendered = stackLayout.Height;
var animation = new Animation(d => stackLayout.HeightRequest = d, start: 0, end: heightWhenRendered, easing: Easing.CubicInOut);
this._runningAnimations.Add(animation);
animation.Commit(stackLayout, "Expand", finished: (x,s) =>
{
this._runningAnimations.Remove(animation);
});