首页 > 解决方案 > Zxing 和 Xamarin 形式

问题描述

我用 xamarin 形式制作了一个应用程序,它必须使 wark 的所有东西都很好,现在我正试图让它变得更好一点。

该应用程序现在创建一个文章列表视图(仅代码和描述),从我服务器上的 API 获取它们,当我点击列表视图的项目时,它会显示更多信息和该文章的价格。我已经安装了 Zxing 包来直接读取 ean_code 并跳过列表视图。来自服务器的 API 工作(尝试使用 Postman),但在应用程序上它给我一个错误“值不能为空。参数名称:stringToEscape”

这是我插入搜索过滤器或单击以阅读 Ean_code 的页面代码:

    public void TapArticolo(object sender, ItemTappedEventArgs e)
    {
        Articolo Articolo_selezionato = (Articolo) ((ListView)sender).SelectedItem; //Link the tapped Item to the class variabile
        Navigation.PushModalAsync(new SchedaArticoloPage(Articolo_selezionato)); // Call the new page passing the class like parameter (Only Cod_articolo and Descr_1)
    }

    private void Button_Ean_Clicked(object sender, EventArgs e)
    {
        var scan = new ZXingScannerPage();
        Navigation.PushModalAsync(scan);
        scan.OnScanResult += (result) =>
        {
            Device.BeginInvokeOnMainThread(async () =>
                {
                    await Navigation.PopModalAsync();
                    Articolo Articolo_selezionato = new Articolo(); // Initialize the Class 
                    Articolo_selezionato.Ean_code = result.ToString(); // Write the Ean code inside the class
                    await Navigation.PushModalAsync(new SchedaArticoloPage(Articolo_selezionato));  // Call the new page passing the class like parameter (Only Ean_Code)
                });
        };
     
    }

这是收集后必须显示详细数据的页面:

public partial class SchedaArticoloPage : ContentPage
{
    public SchedaArticoloPage(Articolo Articolo_selezionato)
    {
        var SchedaArticoloViewModel = new SchedaArticoloViewModel();    //Initialize the ViewModel
        SchedaArticoloViewModel.Articolo_selezionato = Articolo_selezionato;  //Link the given Parameter to the class of the viewModel
        if (Articolo_selezionato.Cod_articolo != null) SchedaArticoloViewModel.Dati_articolo.Execute(null);  // Execute in case of tap (only the Cod_articolo is present)
        if (Articolo_selezionato.Ean_code != null) SchedaArticoloViewModel.Dati_articolo_da_ean.Execute(null);  //Execute in case of Ean code Read (only Ean code present)
        SchedaArticoloViewModel.Listini_Articolo_command.Execute(null); // Retrive price whan all the record of the class are present
        BindingContext = SchedaArticoloViewModel;   //Bind the content
        InitializeComponent();
    }
}

最后,这些是从服务器收集数据的 api:

    public async Task<Articolo> GetAnagraficaArticolo(string AccessToken, string cod_articolo)
    {
        server = Settings.Server;
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
        var json = await client.GetStringAsync(server + "/api/Articolo?cod_articolo=" + Uri.EscapeUriString(cod_articolo));
        var Articolo = JsonConvert.DeserializeObject<Articolo>(json);
        return Articolo;
    }

    public async Task<Articolo> GetAnagraficaArticoloDaEan(string AccessToken, string Ean_Code)
    {
        server = Settings.Server;
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
        var json = await client.GetStringAsync(server + "/api/Articolo?Ean_code=" + Uri.EscapeUriString(Ean_Code));
        var Articolo = JsonConvert.DeserializeObject<Articolo>(json);
        return Articolo;
    }

使用普通代码,它就像一个魅力,使用 ean_code 它崩溃。我真的不知道哪里错了。

在此先感谢您的帮助

标签: restxamarin.formszxing

解决方案


不知道为什么,但改变了连接的手机,它已经开始正常工作了。


推荐阅读