Xamarin.Forms:停止时从 "auto picking and closing" 禁用 iOS 选择器并等待 "DONE" 按钮单击

Xamarin.Forms: Disable iOS picker from "auto picking and closing" when stopped and WAIT for "DONE" button click

我正在使用 xamarin.forms:

中的常规选择器
      <Picker 
x:Name="picker_subcat2_mainmenu" 
                                Margin="10,0,10,0"
                                Grid.Column="3"
                                TitleColor="#ffffff"
                                Title=" + "
                                Grid.Row="1"
                                FontFamily="arial"
                                BackgroundColor="#00000000"
                                TextColor="#ffffff"
                                HorizontalOptions="Center" 
                                VerticalOptions="Center">
                    </Picker>

但是,此选择器在 iOS 上有问题。 它包含一个带有元素的长列表,但是当您停止滚动时,选择器会自动接受突出显示的项目并关闭。但这是一个问题,因为您只能向上拖动手指到此为止。如果列表还没有结束,进入下一个项目是非常挑剔的(你必须用两个手指来提供不间断的触摸)。

如何让选择器仅在 "DONE" 按钮未按下且不再触摸它时关闭?

谢谢!

根据 Picker Item Selection on iOS 文档,Picker 有两种选择:

Immediately – item selection occurs as the user browses items in the Picker. This is the default behavior in Xamarin.Forms.

WhenFinished – item selection only occurs once the user has pressed the Done button in the Picker.

在你的情况下你想要第二个。

如果您的代码在 xml 中,您可以这样做:

<ContentPage ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout Margin="20">
        <Picker ... Title="Select a monkey" ios:Picker.UpdateMode="WhenFinished">
          ...
        </Picker>
        ...
    </StackLayout>
</ContentPage>

如果您的代码在代码隐藏文件中:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

picker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);

用这个 xmlns:iOSSpecific="clr-命名空间:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"

然后 <选择器 iOSSpecific:Picker.UpdateMode="WhenFinished"