Xamarin.Android在页面之间导航时出现问题

时间:2020-11-04 11:05:08

标签: android xamarin xamarin.android httpclient multipartform-data

我的跨平台应用程序中有一个错误。 我有一个带有文档(文件夹)列表的页面,当我单击其中一个时,我有一些按钮可以添加一些照片(将文件添加到文档文件夹中)并将其发送到url。 因此,执行流程如下:

DocumentList-> DocumentEditor-> AddPhotos

在DocumentEditor中,如前所述,我可以通过client.postAsync(String Url,MultipartFormDataContent)将文档(和相关照片)发送到url。在此操作过程中我没有任何问题,但是当我按下导航栏中的“后退”按钮时。

我回到上一页(DocumentList),但是标题被剪切掉了,如果我想选择另一个文档,它会打开一个黑色的DocumentEditor页面。

如果我不发送文档,则返回按钮没有任何问题,因此client.postAsync肯定存在问题。

有什么想法吗?

一些图片:

postAsync之前的DocumentList:

enter image description here

postAsync之前的DocumentEditor:

enter image description here

按下postAsync和后退按钮后的

DocumentList(注意标题):

enter image description here

在上一个图像中选择文档后,使用DocumentEditor:

enter image description here

一些代码:

在DocumentList中单击处理程序:

private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
        Grid Cell = ((Grid)sender);
        String DirName = Cell.FindByName<Label>("DirName").Text;
        await Navigation.PushAsync(new DocumentEditor(DirName, Type));
    }

SendDocument按钮处理程序:

private async void InviaDocumento_Clicked(object sender, EventArgs e)
    {

        bool response await DisplayAlert("Invio", "Vuoi davvero inviare il documento?", "Si", "No");

        if (response)
        {
            String url = some codes...
            ...
            MultipartFormDataContent multiContent = new MultipartFormDataContent();
            ...SomeCodes to populate multiContent...
            HttpClient client = new HttpClient();

            client.Timeout = TimeSpan.FromMinutes(2);

            HttpResponseMessage response2 = await client.PostAsync(url, multiContent);
            if (response2.StatusCode == HttpStatusCode.OK)
                {
                    await DisplayAlert("Upload", "Upload completato con successo!", "Ok");
                    //await Navigation.PopToRootAsync();
                }
                else
                {
                    string error = await response2.Content.ReadAsStringAsync();
                    await DisplayAlert("Errore", "Si è verificato un errore durante l'upload: " + error, "Ok");
                }
         }
  }

编辑:

在ios上运行良好,在android上,即使使用执行Navigation.PopAsync()的按钮,此问题仍然存在。

0 个答案:

没有答案