英文:
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:
<ContentPage ...
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls">
<StackLayout>
<ListView ... ios:ListView.RowAnimationsEnabled="false">
...
</ListView>
</StackLayout>
</ContentPage>
Alternatively, it can be consumed from C# using the fluent API:
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...
listView.On<iOS>().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<ListView> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论