如何将 PageRenderer/Fragment/View 中的 ZXing 扫描器嵌入到 Xamarin.Forms ContentPage 中? [英] How to embed ZXing scanner in PageRenderer/Fragment/View into Xamarin.Forms ContentPage?

查看:22
本文介绍了如何将 PageRenderer/Fragment/View 中的 ZXing 扫描器嵌入到 Xamarin.Forms ContentPage 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 ZXing.Net.Mobile 条码扫描器具有自定义叠加层和一些在 Xamarin.Forms 中实现的 UI 组件在一个视图中.有可能吗?

I want to have ZXing.Net.Mobile barcodes scanner with a custom overlay and some UI components implemented in Xamarin.Forms in one View. Is it possible at all?

我认为这是可能的并实现了这一点:1. Android.Support.V4.App.FragmentActivity 带有 ZXing 扫描仪的自定义叠加层.2. 带有 ZXing 扫描仪自定义叠加层的 Android Activity.3. 带有 ZXing 扫描仪自定义叠加层的 Android PageRenderer.

I assumed that this is possible and implemented this: 1. Android.Support.V4.App.FragmentActivity with a custom overlay for ZXing scanner. 2. Android Activity with a custom overlay for ZXing scanner. 3. Android PageRenderer with a custom overlay for ZXing scanner.

我能够运行所有这些变体,但我无法将它们与 Xamarin.Forms UI 混合使用.

I was able to run all these variants, but I was not able to mix them with Xamarin.Forms UI.

示例:这是我在共享项目中的 ZXingScannerRendererPage.xaml.我想在 Zxing 扫描仪视图上方有测试按钮"按钮.

Example: Here is my ZXingScannerRendererPage.xaml in the shared project. I want to have "TEST BUTTON" button above Zxing Scanner view.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage x:Name="RootPage"
    BackgroundColor="{StaticResource BackgroundColor}"
    xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:views="clr-namespace:DataCollector" x:Class="DataCollector.ZXingScannerRendererPage">
    <ContentPage.Content>
        <StackLayout>
            <Button Text="TEST BUTTON" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

但是当我使用 PageRenderer 运行应用程序时,我可以使用TEST BUTTON"查看我的布局,然后视图跳转到 ZXing 扫描仪.当我按下后退"按钮时,我可以看到带有测试按钮"的 XAML 布局.我觉得ZXing开了个新活动什么的.

But when I run the application with PageRenderer I can see for a second my layout with "TEST BUTTON" and then view jumps to ZXing scanner. When I "press back" button, I can see my XAML layout with "TEST BUTTON". I think ZXing opens a new activity or something.

所以,我需要的是:1. 将带有自定义叠加层的 ZXing.Net.Mobile 条形码扫描仪与其他 Xamarin.Forms UI 一起嵌入到我的 Xamarin.Forms ContentPage 中.或者2. 将 Xamarin.Forms UI 嵌入到带有自定义覆盖的 ZXing.Net.Mobile 条码扫描器的视图上方.

So, what I need is: 1. Embed ZXing.Net.Mobile barcodes scanner with custom overlay into my Xamarin.Forms ContentPage along with other Xamarin.Forms UI. or 2. Embed Xamarin.Forms UI above view with ZXing.Net.Mobile barcodes scanner with a custom overlay.

如何实现?是否可以将 PageRenderer/Fragment/View 嵌入到 Xamarin.Forms XAML 中?

How to accomplish this? Is it possible to embed PageRenderer/Fragment/View into Xamarin.Forms XAML?

谢谢!

推荐答案

如何实现?是否可以将 PageRenderer/Fragment/View 嵌入到 Xamarin.Forms XAML 中?

How to accomplish this? Is it possible to embed PageRenderer/Fragment/View into Xamarin.Forms XAML?

您可以将扫描仪视图嵌入到其他冗余 BoxView 之间.

You could embed the scanner view in between to other redundant BoxViews.

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="ZXingSample.PartialScreenScanning"
                    xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
                    Title="Partial screen">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <BoxView Grid.Row="0" BackgroundColor="Chocolate"/>
    <zxing:ZXingScannerView Grid.Row="1" x:Name="_scanView" OnScanResult="Handle_OnScanResult" IsScanning="true"
                            WidthRequest="200" HeightRequest="200" />
    <BoxView Grid.Row="2" BackgroundColor="Blue" />
</Grid>

您可以从 GitHub 下载源文件.https://github.com/jfversluis/ZXingSample

You could download the source file from the GitHub. https://github.com/jfversluis/ZXingSample

这个博客也会很有帮助.https://blog.verslu.is/xamarin/xamarin-forms-xamarin/scanning-generating-barcodes-zxing/

This blog would be helpful as well. https://blog.verslu.is/xamarin/xamarin-forms-xamarin/scanning-generating-barcodes-zxing/

这篇关于如何将 PageRenderer/Fragment/View 中的 ZXing 扫描器嵌入到 Xamarin.Forms ContentPage 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆