I have a xamarin picker with a list of items and I want to remove the picker when the "done" button is pressed on iPhone and "Oke" button on android.
I have the code to remove the picker. But i don't know what event_Handler that might by.
Code:
Picker picker = new Picker
{
Title = "What's in the slot?",
VerticalOptions = LayoutOptions.CenterAndExpand
//HorizontalOptions = LayoutOptions.Center
};
private void Displaypickerview(int row, int column)
{
if (status == "filling board")
{
foreach (string text in pickerText)
{
picker.Items.Add(text);
}
foreach (string ore in oreLevels)
{
picker.Items.Add(ore);
}
picker.SelectedIndexChanged += (sender, args) =>
{
if (picker.SelectedIndex == -1)
{
}
else
{
//change value of cell and button
Picker picker = (Picker)sender;
int index = picker.SelectedIndex;
if (index < pickerText.Length)
{
board[row, column].Text = pickerText[index - 1];
}
else {
board[row, column].Text = oreLevels[index - 1 - pickerText.Length];
}
}
};
}
else if (status == "choosing item")
{
}
}
Example of what it looks like on iPhone:
There is now a platform specific configuration option that lets you enable this on iOS.
You specify a PickerMode
on a specific picker to only select once someone hits done on iOS.
<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>
The Picker.On<iOS>
method specifies that this platform-specific will only run on iOS. The Picker.SetUpdateMode method, in the Xamarin.Forms.PlatformConfiguration.iOSSpecific
namespace, is used to control when item selection occurs, with the UpdateMode enumeration providing two possible values:
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.
Read docs for more info on control. https://docs.microsoft.com/sr-latn-rs/xamarin/xamarin-forms/platform/ios/picker-selection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With