问题描述
我在ItemTemplate
中使用了Picker
,并且其值是通过绑定设置的.
I use a Picker
in an ItemTemplate
and its Value is set via binding.
第一次显示我的ListView
时,它会显示值.
When my ListView
is shown first time, it shows the value.
当我打开其列表并设置值时,Picker
保持为空.
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).
这是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>
什么可以清除价值?
奖金:Windows Phone 8.1中的文本颜色为白色 ...再次设置为Black
颜色.
Bonus: the text color is white in Windows Phone 8.1...agains the set Black
color.
这是用户界面:
这是Visual Studio中的实际值:
Here are the actual values in Visual Studio:
推荐答案
好吧,根据此.
幸运的是",报告中提供了一种变通方法,可帮助使SelectedItem
出现.
"Fortunately", there is a workaround in the report that helps to make the SelectedItem
appear.
您应该创建一个不可见的Label
并将其Text
属性绑定到Picker
的SelectedItem
.
You should create an invisible Label
and bind its Text
property to the SelectedItem
of the Picker
.
在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}'}" />
这篇关于选择器未在Windows Phone和UWP的Xamarin.Forms中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!