![](/img/trans.png)
[英]Going through RPG inventory, how to display items by character class type while maintaining modularity?
[英]How to display spinning wheel while going through all updating routines?
我目前正在研究一些用Xamarin.Forms编写的移动项目。 我在这里有一个问题。 我需要更新包含一些数据的列表视图。 所以我启用了IsPullToRefreshEnabled = true
和
listView.Refreshing += (sender, e) => {
method1();
method2();
listView.EndRefresh();
};
但是,我不确定如何在所有更新例程完成之前如何显示旋转指示器。
public class Class1 : ContentPage
{
readonly Class2 mangr = new Class2();
void BuildUI()
{
listView = new ListView
{
ItemsSource = new object[] { },
ItemTemplate = new DataTemplate(listRender.MakeCell),
RowHeight = 88,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
IsPullToRefreshEnabled = true,
IsRefreshing = false,
};
listView.Refreshing += (sender, e) =>
{
listView.IsRefreshing = true;
manager.ForceUpdate();
listView.IsRefreshing = false;
listView.EndRefresh();
};
}
}
public class Class2
{
public bool updating = false;
public void PleaseUpdate()
{
if (!running)
{
return;
}
if (!data.loading)
{
updating = true;
PleaseUpdate();
updating = false;
}
}
void PleaseUpdate(Action afterall = null){/some code/}
}
您是说PullToRefresh ActivityIndicator吗? 为此,您必须将IsRefreshing
属性设置为true
。 因此,只需在开始时将其设置为true
,并在准备就绪时将其设置为false
,就像这样。
listView.Refreshing += (sender, e) => {
listView.IsRefreshing = true;
method1();
method2();
listView.IsRefreshing = false;
listView.EndRefresh();
};
如果方法是async
这将不起作用,因为它将直接转到IsRefreshing = false
。
有多种方法可以执行此操作,运行它们同步(这可能不是您想要的)或创建绑定到listView.IsRefreshing
属性的公共属性。 然后从真正完成加载的位置设置该属性!
更新资料
当您提供代码时,一种解决方法是这样的:
listView.IsRefreshing
设置为pumpsManager.isLoading
FuelPumpsDataManager
并实现它的isLoading
。 注意,您需要将“ isLoading”转换为属性。 另一种简化此操作的方法是使用PropertyChanged.Fody NuGet包。 现在,您可以在isLoading
开始和停止加载时进行设置,并且ListView应该相应地显示动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.