选择器未在Windows

选择器未在Windows

本文介绍了选择器未在Windows Phone和UWP的Xamarin.Forms中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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属性绑定到PickerSelectedItem.

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中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:05