Nestor
Nestor

Reputation: 8384

Picker not showing value in Xamarin.Forms on Windows Phone and UWP

I use a Picker in an ItemTemplate and its Value is set via binding.

When my ListView is shown first time, it shows the value.

enter image description here

When I open its list, and set the value, the Picker remains empty.

enter image description here

enter image description here

If I open the list again, it shows the previously set value (also the binded object holds the correct value).

enter image description here

This is the XAML:

<Picker x:Name="picker"
      Grid.Row="0"
      Grid.Column="2"                                        
      SelectedIndex="{Binding MyValue}"
      TextColor="Black"
      VerticalOptions="Center"
      WidthRequest="70">
  <Picker.Items>
      <x:String>Start value</x:String>
      <x:String>1</x:String>
      <x:String>2</x:String>

What clears off the value?

Bonus: the text color is white in Windows Phone 8.1...agains the set Black color.

Here is the UI:

enter image description here

Here are the actual values in Visual Studio:

enter image description here

Upvotes: 0

Views: 1483

Answers (1)

Nestor
Nestor

Reputation: 8384

Well, it is a known bug in Xamarin.Forms according to this.

"Fortunately", there is a workaround in the report that helps to make the SelectedItem appear.

You should create an invisible Label and bind its Text property to the SelectedItem of the Picker.

In XAML:

<Picker x:Name="pickerIn">
  <Picker.Items>
    <x:String>In - A</x:String>
    <x:String>In - B</x:String>
    <x:String>In - C</x:String>
  </Picker.Items>
</Picker>
<Label IsVisible="False" Text="{Binding Source={x:Reference pickerIn}, Path=SelectedIndex,StringFormat='The picker inside of TableView has index={0}'}" />

Upvotes: 1

Related Questions