我正在使用 Xamarin-forms 编写应用程序。当我使用 popAsync()
离开编辑列表的页面时,我想刷新上一页的列表,以便显示我的更改。
我的 PopulateMachineSelectionList()
将我的 machine
对象添加到列表中。
这是我目前尝试过的
protected override void OnAppearing()
{
PopulateMachineSelectionList();
base.OnAppearing();
}
async void PopulateMachineSelectionList()
{
loadedMachines = await machineSync.GetMachines();
if (loadedMachines.Count() != 0)
{
machineSelectionList.Clear();
foreach (Machine mach in loadedMachines)
{ //I have an archive boolean that determines whether or not machines should be shown
if (!mach.archived)
{
Console.WriteLine("Adding: " + mach.name + " to the list template");
machineSelectionList.Add(new ListTemplate(null, mach.name, true, true));
}
}
Console.WriteLine("Refresh List");
machineList.ItemsSource = machineSelectionList;
}
machineList.SelectedItem = null;
}
最佳答案
尝试类似下面的代码:
machineList.ItemsSource.Clear();
machineList.ItemsSource.Add(machineSelectionList);
这可能会触发 propertychanged
事件。
关于c# - Xamarin - PopAsync() 后刷新列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44406021/