Xamarin表格淡出隐藏?

Abr*_*Ali 4 xamarin xamarin.forms

在我当前的应用程序中,我有一堆按钮可以隐藏或显示相应的stackLayout.首先,我尝试使用IsVisble属性,但这会导致闪光,现在我正在使用LayoutTo(),它也会闪烁?

我的代码如下:

async void btnStrike_Clicked(object sender, EventArgs args)
        {
            var layout = this.FindByName<StackLayout>("stkStrikeInfo");
            var rect = new Rectangle(layout.X, layout.Y, layout.Width, layout.Height - layout.Height);
            await layout.LayoutTo(rect, 2500, Easing.Linear);
        }
Run Code Online (Sandbox Code Playgroud)

我喜欢动画高度!

编辑:

我找到了以下代码,它从页面中删除了Stacklayout.现在的问题是视图没有更新?

Wil*_*ker 12

我认为你只需要一个默认动画就可以获得更好的运气,它可以将要隐藏的布局高度降低到零.

void btnStrike_Clicked(object sender, EventArgs args)
{
    // get reference to the layout to animate
    var layout = this.FindByName<StackLayout>("stkStrikeInfo");

    // setup information for animation
    Action<double> callback = input => { layout.HeightRequest = input; }; // update the height of the layout with this callback
    double startingHeight = layout.Height; // the layout's height when we begin animation
    double endingHeight = 0; // final desired height of the layout
    uint rate = 16; // pace at which aniation proceeds
    uint length = 1000; // one second animation
    Easing easing = Easing.CubicOut; // There are a couple easing types, just tried this one for effect

    // now start animation with all the setup information
    layout.Animate("invis", callback, startingHeight, endingHeight, rate, length, easing);
}
Run Code Online (Sandbox Code Playgroud)

如果布局已隐藏并且您想要显示它,则可以替换

double startingHeight = layout.Height;
double endingHeight = 0;
Run Code Online (Sandbox Code Playgroud)

double startingHeight = 0;
double endingHeight = 55;
Run Code Online (Sandbox Code Playgroud)

55只是一个任意高度,如果你想让它回到以前的高度,你可以在隐藏它之前将之前的高度保存到变量并使用保存的高度而不是55.