Reputation: 8384
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.
When I open its list, and set the value, the Picker
remains empty.
If I open the list again, it shows the previously set value (also the binded object holds the correct value).
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:
Here are the actual values in Visual Studio:
Upvotes: 0
Views: 1483
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