Xamarin表格会淡化为隐藏吗? [英] Xamarin Forms fade to hidden?

查看:96
本文介绍了Xamarin表格会淡化为隐藏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my current app, I have a bunch of buttons which can hide or show their corresponding stackLayout. First, i tried using IsVisble property, but this causes a flash, now im at using LayoutTo() which also flashes?

我的代码如下:

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);
        }

我想动画化身高!

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

I found the following piece of code, which removes the Stacklayout from the page. The issue now is that the view isnt updating?

推荐答案

我认为,只要使用默认动画即可将要隐藏的布局高度降低为零,您会获得更好的运气.

I think you'll have better luck with just a default animation that reduces the height of the layout you want to hide to zero.

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);
}

如果布局已经隐藏并且要显示,请替换

If the layout is already hidden and you want to show it, you would replace

double startingHeight = layout.Height;
double endingHeight = 0;

double startingHeight = 0;
double endingHeight = 55;

55只是一个任意高度,如果您希望它回到以前的高度,则可以在隐藏之前将以前的高度保存到一个变量中,然后使用保存的高度代替55.

The 55 is just an arbitrary height, if you want it to go back to the height from before, you would save the previous height to a variable before you hide it and use that saved height instead of 55.

这篇关于Xamarin表格会淡化为隐藏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆