Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.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.forms中的异步页面加载_C#_Asynchronous_Xamarin - Fatal编程技术网

C# xamarin.forms中的异步页面加载

C# xamarin.forms中的异步页面加载,c#,asynchronous,xamarin,C#,Asynchronous,Xamarin,我目前正在开发一个基于主细节模板的小应用程序。我的一个页面要求立即加载一些数据,我不知道该怎么做。在每个示例中,只要用户按下一个按钮,就会加载数据 这是我目前的代码: string test = async (sender, e) => { Task<string> json = GetRandomRelations (); return await json; }; string test=async(发送方,e)=>{ TaskJSON=GetRando

我目前正在开发一个基于主细节模板的小应用程序。我的一个
页面
要求立即加载一些数据,我不知道该怎么做。在每个示例中,只要用户按下一个按钮,就会加载数据

这是我目前的代码:

string test = async (sender, e) => {

    Task<string> json = GetRandomRelations ();
    return await json;
};
string test=async(发送方,e)=>{
TaskJSON=GetRandomRelations();
返回等待json;
};
还有我的方法

public async Task<string> GetRandomRelations () {

        var client              = new System.Net.Http.HttpClient ();
        client.BaseAddress      = new Uri("http://127.0.0.1/loltools/web/app_dev.php/api/relation/");
        string response         = await client.GetStringAsync("random/20");

        return response;
    }
公共异步任务GetRandomRelations(){
var client=new System.Net.Http.HttpClient();
client.BaseAddress=新Uri(“http://127.0.0.1/loltools/web/app_dev.php/api/relation/");
字符串响应=wait client.GetStringAsync(“随机/20”);
返回响应;
}
我目前正在尝试获取json响应,但我甚至无法做到这一点。。。我的主要问题是无法将lambda表达式转换为字符串


谢谢你的帮助

我不完全确定您想做什么,但简单地说:

string test = await GetRandomRelations ();
我的一个页面需要立即加载一些数据,但我不知道如何做到这一点

想想这个。你真正想问的是如何协调两个相反的要求:

  • 页面必须立即显示一些数据。用户界面必须具有响应性。数据必须同步可用才能显示
  • 数据是异步检索的。现在还没有。甚至需要一些(未知的)时间才能显示数据

  • 所以,显然,没有直接的解决办法。相反,您必须以不同的方式满足这两个核心需求(“UI必须具有响应性”和“异步检索数据”)。一种常见的方法是(立即和同步地)显示数据的“加载…”视图—微调器或诸如此类的东西。然后,在数据到达时更新显示。

    是的,我当前正在页面中显示加载程序,但我不知道如何对其进行编码。你有什么例子吗?@solarbana:我从来没有使用过Xamarin表单,但我认为
    INotifyPropertyChanged
    应该可以做到这一点。为了使用
    wait
    ,它需要一个
    async
    方法。似乎不是默认情况下页上存在的
    异步void PageFinishedRendering()
    方法。