xamarin.forms, . , , , .
, - OnItemSelected, DetailView, . DetailView . , , .
, : SomePage SomeView. , , , .
SomeView
SomeView , , ajax. :
Forms, .
class SomeView : Form
{
void ShowVisualFeedBack()
{
...
}
void HideVisualFeedBack()
{
...
}
public async Task LoadDataAsync()
{
bool result = false;
this.ShowVisualFeedBack()
try
{
this.itemList = await WebService.Instance.GetData();
result = true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
this.HideVisualFeedBack();
return result;
}
}
, 5 , :
try
{
await Task.Delay(TimeSpan.FromSeconds(5));
this.itemList = await WebService.Instance.GetData();
result = true;
}
SomePage
class SomePage : Form
{
void ShowVisualFeedBack()
{
...
}
void HideVisualFeedBack()
{
...
}
private async Task ShowDetailView()
{
this.ShowVisualFeedBack();
this.DetailView = new MyView();
await view.LoadContent();
this.HideVisualFeedBack();
}
}
By the way, while your thread is expecting GetData (), it cannot update your visual feedback. Some visual feedback methods, such as GIFs, do not need updates to your stream, but if you have something like a progress bar, your stream should update it. You can do this by waiting for the maximum time until GetData completes, refresh the move and wait again
var taskWaitASec = Task.Delay(TimeSpan.FromSeconds(1));
var taskGetData = WebService.Instance.GetData();
while (!taskGetData.IsCompleted)
{
var myTasks = new Task[] {taskWaitASec, taskGetData}
var completedTask = await Task.WhenAny(myTasks);
if (completedTask == taskWaitASec)
{
UpdateProgress();
taskWaitASec = Task.Delay(TimeSpan.FromSeconds(1));
}
}
source
share