我正在构建一个Xamarin Forms应用程序并且状态栏(iOS)中的网络活动微调器有问题继续永久旋转。以下是我用来显示加载屏幕的代码。
private async Task ExecuteConfigureCampaignCommand()
{
if (IsBusy)
{
return;
}
IsBusy = true;
//ConfigureCampaignCommand.ChangeCanExecute();
bool showAlert = false;
string campaign = null;
try
{
campaign = CrossSecureStorage.Current.GetValue(SettingNames.Campaign);
if (!String.IsNullOrEmpty(campaign))
{
StatusMessage = "Blah";
OnPropertyChanged("StatusMessage");
await Task.Delay(1000);
StatusMessage = "Blah";
OnPropertyChanged("StatusMessage");
await Task.Delay(700);
StatusMessage = "Blah";
OnPropertyChanged("StatusMessage");
await Task.Delay(500);
MessagingService.Current.SendMessage<string>(SettingNames.NavigationSales, campaign);
}
}
catch (Exception e)
{
var abc = e;
showAlert = true;
}
finally
{
IsBusy = false;
//ConfigureCampaignCommand.ChangeCanExecute();
}
if (showAlert)
{
await page.DisplayAlert("Uh Oh :(", "Unable to load campaign.", "OK");
}
}
这是从命令调用的:
public Command ConfigureCampaignCommand
{
get
{
return configureCampaignCommand ?? (configureCampaignCommand = new Command(async () => await ExecuteConfigureCampaignCommand(), () => { return !IsBusy; }));
}
}
从OnAppearing调用:
protected override void OnAppearing()
{
base.OnAppearing();
viewModel.ConfigureCampaignCommand.Execute(null);
}
逻辑很好 - 我期望加载的视图,但网络活动微调器继续旋转。如果我加1秒延迟:
Device.StartTimer(TimeSpan.FromMilliseconds(1), () =>
{
MessagingService.Current.SendMessage<string>(SettingNames.NavigationSales, campaign);
return false;
});
加载新视图后,微调器停止。如果我删除await Task.Delay,则一旦加载了视图,微调器就会停止,但加载消息对用户不可见。
我的问题是,为什么网络微调器继续?
答案 0 :(得分:0)
每当你改变IsBusy
OnPropertyChanged("IsBusy");
正如你所说的那样是为了你的其他财产而不是IsBusy,我想这可能是改变没有被接受的原因。