I have trouble to get out the selected string
from my picker.
This is my code:
XAML:
<Picker x:Name="thePicker" >
<Picker.Items>
<x:String>info1</x:String>
<x:String>info2 </x:String>
</Picker.Items>
</Picker>
CODE:
thePicker.SelectedIndex = 1; //here is the problem i suppose, any idea what i should type?
var ourPickedItem = thePicker.Items[thePicker.SelectedIndex];
Now I only get the value "info1" even if i select number 2. It has something to do with the SelectedIndex
so it only picks the "1", but I am not sure how to write the code to make it work for the selected item.
The Xamarin. Forms SfPicker allows to get current selected date using the SelectedItem property. In the selection changed event, use the selected item property to get the current selected Xamarin.
When binding to a list of objects, the Picker must be told which property to display from each object. This is achieved by setting the ItemDisplayBinding property to the required property from each object. In the code examples above, the Picker is set to display each Monkey.Name property value.
You should take a look at this:
picker.SelectedIndexChanged += (sender, args) =>
{
if (picker.SelectedIndex == -1)
{
boxView.Color = Color.Default;
}
else
{
string colorName = picker.Items[picker.SelectedIndex];
boxView.Color = nameToColor[colorName];
}
};
Otherwise in new Xamarin Forms Release 2.3.4 exists the
Bindable Picker
you can set an ItemSource
<Picker ItemsSource="{Binding Countries}" />
and Bind the SelectedIndex property
SelectedIndex="{Binding CountriesSelectedIndex}"
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