当您在 Zebra TC21 上运行的 Maui 应用程序中扫描第一个条目中的条形码时,会添加一个 Enter 键,并且焦点会移至第二个条目。当您扫描第二个条目中的条形码时,应用程序会比较第一个和第二个条目的值并输出不同的声音,但它无法识别第二个条目中的回车键。但是,当我按下 Android 手机上的物理 Enter 键时,它会被识别并播放声音。请帮助我。
在Zebra tc21上扫描条码时,回车键正确通过,因此焦点正常移动到entrySecond。为什么entrySecond不能识别条码扫描器的回车键,而只能识别物理键盘的回车键?
这是您问题的演示代码:
public partial class MainViewModel : ObservableObject
{
[RelayCommand]
public async Task Done()
{
await Shell.Current.DisplayAlert("Done","Done","Done");
}
[RelayCommand]
public async Task Done2()
{
await Shell.Current.DisplayAlert("Done2", "Done2", "Done2");
}
}
在 XAML 中:
<ScrollView>
<VerticalStackLayout>
<Entry WidthRequest="100"
ReturnCommand="{Binding DoneCommand}"/>
<Entry WidthRequest="100"
ReturnCommand="{Binding Done2Command}"/>
</VerticalStackLayout>
</ScrollView>
这就足够了,扫描后焦点将从第一个条目移动到第二个条目,并且在良好阅读后将显示警报。
当然,我没有这个斑马模型,但我有带有条形码扫描仪的移动设备,设置为在读取值(换行)后格式化 [LF]。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:viewmodels="clr-namespace:isSame2023.ViewModels"
xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
x:DataType="viewmodels:BarcodeViewModel"
x:Class="isSame2023.Views.ScanPage"
Title="ScanPage">
<ContentPage.BindingContext>
<viewmodels:BarcodeViewModel/>
</ContentPage.BindingContext>
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0,50,0,0"/>
<On Platform="Android" Value="2,2,2,2"/>
</OnPlatform>
</ContentPage.Padding>
<VerticalStackLayout>
<Frame BackgroundColor="#2196F3" Padding="20" CornerRadius="0">
<Label Style="{StaticResource LargeLabel}" Text="Safe Combine Ver 1.0" HorizontalTextAlignment="Center" TextColor="White" FontSize="30" />
</Frame>
<toolkit:MediaElement
x:Name="mediaElement"
>
</toolkit:MediaElement>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <!-- 0 -->
<RowDefinition Height="10"/> <!-- 1 -->
<RowDefinition Height="Auto"/> <!-- 2 -->
<RowDefinition Height="Auto"/> <!-- 3 -->
<RowDefinition Height="10"/> <!-- 4 -->
<RowDefinition Height="Auto"/> <!-- 5 -->
<RowDefinition Height="Auto"/> <!-- 6 -->
<RowDefinition Height="Auto"/> <!-- 7 -->
<RowDefinition Height="10"/> <!-- 8 -->
<RowDefinition Height="Auto"/> <!-- 9 -->
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="270"/>
</Grid.ColumnDefinitions>
<Label Style="{StaticResource MediumLabel}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
Text="Tick! Tick! Tick!" HorizontalOptions="Center"
FontSize="Body"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="2" Grid.Column="0" Text="1st Scaned Value:" HorizontalOptions="End"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="2" Grid.Column="1" Text="{Binding FirstScan}"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="3" Grid.Column="0" Text="2nd Scaned Value:" HorizontalOptions="End"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="3" Grid.Column="1" Text="{Binding SecondScan}"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="5" Grid.Column="0" Text="1st Scan:" VerticalOptions="Center" HorizontalOptions="End"/>
<Entry android:Entry.ImeOptions="Default" Style="{StaticResource SmallEntry}" x:Name="entryFirst" Grid.Row="5" Grid.Column="1" Placeholder="Please 1st Scan"
Text="{Binding FirstScan}" VerticalOptions="Center"/>
<Label Style="{StaticResource SmallLabel}" Grid.Row="6" Grid.Column="0" Text="2nd Scan:" HorizontalOptions="End"/>
<Entry android:Entry.ImeOptions="Default" Style="{StaticResource SmallEntry}" x:Name="entrySecond" Grid.Row="6" Grid.Column="1" Placeholder="Please 2nd Scan"
Text="{Binding SecondScan}" ReturnCommand="{Binding PlaySoundCommand}"/>
<Button x:Name="BtnInitialize" Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" Text="Initialize" Clicked="BtnInitialize_Clicked"/>
</Grid>
</VerticalStackLayout>
</ContentPage>