Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以Xamarin的形式进行简单的isPulledToRefresh?_C#_Xamarin_Xamarin.forms - Fatal编程技术网

C# 如何以Xamarin的形式进行简单的isPulledToRefresh?

C# 如何以Xamarin的形式进行简单的isPulledToRefresh?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我在XAML中已启用isPulledToRefresh(true),并且我的listviews名称为“EmployeeList”。下面这段代码我一直在使用,但它不起作用 public static List<createSomething> ourPitems = new List <createSomething>(); public StartPage() { InitializeComponent(); loadOurList(); } void

我在XAML中已启用isPulledToRefresh(true),并且我的listviews名称为“EmployeeList”。下面这段代码我一直在使用,但它不起作用

public static List<createSomething> ourPitems = new List <createSomething>();

public StartPage()
{
    InitializeComponent();
    loadOurList();
}

void loadOurList()
{
    EmployeeList.BeginRefresh();
    EmployeeList.ItemsSource = ourPitems;
    EmployeeList.EndRefresh();
}
publicstaticlist-ourPitems=newlist();
公共起始页()
{
初始化组件();
loadOurList();
}
void loadOurList()
{
EmployeeList.BeginRefresh();
EmployeeList.ItemsSource=ourPitems;
EndRefresh();
}
“装载轮”一直在旋转。
(createSomething是我的公共类,但我想我不必显示该代码)。

只要创建一个命令,在用户下拉列表视图时执行:

public ICommand LoadDataCommand { get; set; }

public StartPage()
{ 
    ...
    BindingContext = this;
    LoadDataCommand = new Command(RefreshData);
    RefreshData();
}

private async void RefreshData()
{
    Items = new ObservableCollection<SomeItem>();  // Load Data and set
    IsRefreshing = false;
}

public ObservableCollection<SomeItem> Items { get; set; }
public ICommand LoadDataCommand{get;set;}
公共起始页()
{ 
...
BindingContext=这个;
LoadDataCommand=新命令(刷新数据);
刷新数据();
}
私有异步void RefreshData()
{
Items=newobserveCollection();//加载数据并设置
IsRefreshing=假;
}
公共ObservableCollection项{get;set;}
在XAML中,绑定命令、项目和IsRefreshing属性:

<ListView x:Name="EmployeeList" IsPullToRefreshEnabled="True" RefreshCommand="{Binding LoadDataCommand}" IsRefreshing="{Binding IsRefreshing}" ItemsSource="{Binding Items}"/>

您应该创建一个命令并将其与ListView关联,
我的Github中有一个例子

找不到:ICommand,ObservableCollection。因为xamarin找不到它,所以给我错误。ICommand在System.Windows.Input中,但您也可以使用命令(xamarin.Forms)。可以在System.Collections.ObjectModelNop中找到ObservableCollection,但它不起作用。知道它会在哪里失败吗?代码本身运行,但没有得到我们想要的结果。