c# – Xamarin表单设置Picker SelectedItem

我正在使用xamarin Forms.
我正在使用Picker for DropDownList.

如何将selectedItem设置为Picker?

我的代码

<Picker x:Name="VendorName" Title="Select" ItemDisplayBinding="{Binding VendorName}" SelectedItem="{Binding VendorName}" Style="{StaticResource PickerStyle}"></Picker>

和服务器端代码是

Device.BeginInvokeOnMainThread(() =>
{
VendorName.ItemsSource = VendorList;
});

var currentVendor = new List<Vendor>();
currentVendor.Add(new Vendor { VendorID = "111", VendorName = "aaaa" });

VendorName.SelectedItem = currentVendor;

解决方法:

这可能不是最有效的,但您可以循环查找索引并设置该方式.

for (int x = 0; x <  VendorList.Count; x++)
        {
            if (VendorList[x].VendorName == currentVendor .VendorName )
            {
                VendorName.SelectedIndex = x;
            }
        }
上一篇:tcp/ip协议


下一篇:计算机网络的知识点(一)