locked
Xamarin.Forms with Components? RRS feed

  • Question

  • User67478 posted

    How can I include a Component (e.g. Zxing.Net.Mobile Barcode Scanner) in a Xamarin.Forms PCL project?

    The component is working for iOS and Android, but you can add a component to the Xamarin.Forms PCL project. If I try I to include the package I get

    Adding ZXing.Net.Mobile... Adding 'ZXing.Net.Mobile 1.4.7.1' to TestZXingExample. Could not install package 'ZXing.Net.Mobile 1.4.7.1'. You are trying to install this package into a project that targets 'portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

    There are other NuGet projects available ... Do I need a NuGet package or should I include a component on each plattform (and how do I use that then)? Or should I include a Xamarin.Forms Shared Project?

    I also tried the ZXing.Net and the Acr.XamForms.BarCodeScanner Nuget packages but I don't know how to start the camera and read a barcode ...

    Monday, March 2, 2015 11:22 AM

Answers

  • User18049 posted

    @anve - The ZXing.Net.Mobile NuGet package supports Android, Windows Phone 8 and iOS (Classic and Unified) projects so it is not possible to install it into a portable class library (PCL) project.

    What you can do is create an interface/abstraction that your PCL project can use, so it is not directly using the Zxing.Net.Mobile NuGet package, and this interface is then fully implemented in the platform specific projects. Using a shared project is another option.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, March 2, 2015 12:19 PM
  • User67478 posted

    OK, I had to include the Acr.BarCodes package in the Xamarin.Forms project and in the plattform specific projects. Samples can be found here.

    But how can I configure the BarCodeScanner instance? (e.g. TopText, BottomText, CancelButtonText, MobileBarcodeScanningOptions)

    I tried this but the text doesn't change:

    buttonScan.Clicked += async (sender, e) => {
        var config = new BarCodeReadConfiguration(){
            TopText = "Scanne deinen BarCode",
            BottomText = "Hier hinhalten",
            CancelText = "Abbrechen"//,
            //Formats = new List<BarCodeFormat>() { BarCodeFormat.EAN_13 }
        };
        var result = await BarCodes.Instance.Read(config);
        System.Diagnostics.Debug.WriteLine(result.Code);
    };
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 3, 2015 10:59 AM

All replies

  • User57869 posted

    The Xamarin Component Store cannot handle Xamarin Forms components yet. I don't know if that's planned for the future.

    You can however add components for each platform to your platform specific projects.

    @JamesMontemagno from Xamarin wrote in his blog that XF plugins should be released as NuGet packages (which are available for free).

    More info on http://motzcod.es/post/104507063997/what-exactly-is-a-plugin-for-xamarin and https://github.com/jamesmontemagno/Xamarin.Plugins

    Monday, March 2, 2015 11:34 AM
  • User18049 posted

    @anve - The ZXing.Net.Mobile NuGet package supports Android, Windows Phone 8 and iOS (Classic and Unified) projects so it is not possible to install it into a portable class library (PCL) project.

    What you can do is create an interface/abstraction that your PCL project can use, so it is not directly using the Zxing.Net.Mobile NuGet package, and this interface is then fully implemented in the platform specific projects. Using a shared project is another option.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, March 2, 2015 12:19 PM
  • User25759 posted

    You can currently use: https://www.nuget.org/packages/Acr.BarCodes until the core ZXing.NET is upgraded to PCL.

    Monday, March 2, 2015 5:14 PM
  • User67478 posted

    @JamesMontemagno: Do you have an example how to use this library?

    Tuesday, March 3, 2015 8:38 AM
  • User67478 posted

    OK, I had to include the Acr.BarCodes package in the Xamarin.Forms project and in the plattform specific projects. Samples can be found here.

    But how can I configure the BarCodeScanner instance? (e.g. TopText, BottomText, CancelButtonText, MobileBarcodeScanningOptions)

    I tried this but the text doesn't change:

    buttonScan.Clicked += async (sender, e) => {
        var config = new BarCodeReadConfiguration(){
            TopText = "Scanne deinen BarCode",
            BottomText = "Hier hinhalten",
            CancelText = "Abbrechen"//,
            //Formats = new List<BarCodeFormat>() { BarCodeFormat.EAN_13 }
        };
        var result = await BarCodes.Instance.Read(config);
        System.Diagnostics.Debug.WriteLine(result.Code);
    };
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 3, 2015 10:59 AM