C# Xamarin。列表中的表单选择器

C# Xamarin。列表中的表单选择器,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我使用的是Xamarin.Form,我的xaml文件中有一个选择器: <Picker Title="Select Communities" ItemsSource="{Binding areas}" ItemDisplayBinding="{Binding Description}" WidthRequest="400" x:Name="CommunityPicker" /> 以下是它的人口增长方式: 在代码隐藏中: areas = webServi

我使用的是Xamarin.Form,我的xaml文件中有一个选择器:

<Picker Title="Select Communities"
        ItemsSource="{Binding areas}"
        ItemDisplayBinding="{Binding Description}" WidthRequest="400" x:Name="CommunityPicker" />
以下是它的人口增长方式:

在代码隐藏中:

areas = webService.getAreas();
下面是getAreas方法:

public List<AreaClass> getAreas()
        {

            List<AreaClass> areas = new List<AreaClass>();

            try
            {
                using (connection = new SqlConnection(connection))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand("sp", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {

                                AreaClass area = new AreaClass();

                                area.Area = reader["Area"].ToString();
                                area.Description = reader["Description"].ToString();

                                areas.Add(area);
                            }
                        }


                    }

                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            finally
            {
                connection.Close();
            }

            return areas;

        }
公共列表getAreas()
{
列表区域=新列表();
尝试
{
使用(连接=新的SqlConnection(连接))
{
connection.Open();
使用(SqlCommand命令=新的SqlCommand(“sp”,连接))
{
command.CommandType=CommandType.storedProcess;
使用(SqlDataReader=command.ExecuteReader())
{
while(reader.Read())
{
AreaClass面积=新的AreaClass();
area.area=读卡器[“area”].ToString();
area.Description=reader[“Description”].ToString();
面积。添加(面积);
}
}
}
}
}
捕获(例外e)
{
Console.WriteLine(例如Message.ToString());
}
最后
{
connection.Close();
}
返回区;
}

我做错了什么?为什么我的选择器没有被填充?

您只能绑定到公共属性。将
区域
设为公共财产

public List<AreaClass> areas { get; set; }

这很奇怪……我不断收到一个错误,说CommunityPicker不存在清理和重建您的解决方案是的,这很有效……我如何获得它?显示我的模型的描述?@user979331如果您已解决此问题,请将其标记为“回答”,它将帮助其他有类似问题的人。谢谢。
public List<AreaClass> areas { get; set; }
CommunityPicker.ItemsSource = webService.getAreas();