c# - Xamarin - PopAsync() 后刷新列表

标签 c# xamarin xamarin.forms

我正在使用 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/

相关文章:

ios - "error": "InvalidRegistration" while sending push notifications

c# - Xamarin.Forms 选择器默认值

c# - 如何编写动态 Lambda 表达式来访问第 N 个父实体?

c# - 当我将 ConnectionId 添加到组时,我丢失了 Hub 中的所有连接

c# - Entry Xamarin Forms PCL 上的边框半径

java - 绑定(bind) jar 离开启动器图标

ios - 动态移动Xamarin.Forms条目

c# - 多行文本框 - 在回发开始时添加空格

c# - 错误:Make sure that it does not include invalid characters or punctuation and that it is not too long

c# - 如何在 xamarin 表单中的自定义页面渲染器上实现 mapbox?