MAUI ListView动画时间

huangapple go评论58阅读模式
英文:

MAUI ListView animation time

问题

ListView添加项目时,存在默认动画,大约需要1秒钟才能完成淡入动画。是否有减少或完全不使用它的方法,以便可以立即填充ListView?

英文:

When I add items to a ListView, there is some default animation that takes about 1 second for a fade in animation to complete. Is there a way to reduce this or not use it at all so that you can get an instantly populated ListView?

答案1

得分: 1

这个.NET多平台应用UI(.NET MAUI)iOS平台特定控件用于在更新ListView项集合时禁用行动画。在XAML中,通过将ListView.RowAnimationsEnabled可绑定属性设置为false来使用:

<ContentPage ...
             xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls">
    <StackLayout>
        <ListView ... ios:ListView.RowAnimationsEnabled="false">
            ...
        </ListView>
    </StackLayout>
</ContentPage>

或者,可以在C#中使用流畅的API来使用:

using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...

listView.On<iOS>().SetRowAnimationsEnabled(false);

有关更多信息,请查阅文档:iOS上的ListView行动画

英文:

This .NET Multi-platform App UI (.NET MAUI) iOS platform-specific controls whether row animations are disabled when the ListView items collection is being updated. It's consumed in XAML by setting the ListView.RowAnimationsEnabled bindable property to false:

&lt;ContentPage ...
             xmlns:ios=&quot;clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls&quot;&gt;
    &lt;StackLayout&gt;
        &lt;ListView ... ios:ListView.RowAnimationsEnabled=&quot;false&quot;&gt;
            ...
        &lt;/ListView&gt;
    &lt;/StackLayout&gt;
&lt;/ContentPage&gt;

Alternatively, it can be consumed from C# using the fluent API:

using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...

listView.On&lt;iOS&gt;().SetRowAnimationsEnabled(false);

For more information, check document: ListView row animations on iOS.

答案2

得分: 0

对于 Windows(WinUI),我使用了自定义的处理程序/渲染器,您可以在下面看到:

using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Platform;

namespace NGT.CustomViews;

public class CustomListViewRenderer : ListViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
    {
        base.OnElementChanged(e);

        if (this.Control != null)
        {
            this.List.ItemContainerTransitions = null;
        }
    }
}
英文:

For windows (WinUI) I used a custom handler/renderer, which you can see below :

using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Platform;

namespace NGT.CustomViews;

public class CustomListViewRenderer : ListViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs&lt;ListView&gt; e)
    {
        base.OnElementChanged(e);

        if (this.Control != null)
        {
            this.List.ItemContainerTransitions = null;
        }
    }
}

Feel free to ask me a question and I can expand if you need me to.

huangapple
  • 本文由 发表于 2023年5月28日 12:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定