简体   繁体   English

如何在Windows Phone中用对象名称填充列表选择器?

[英]How to fill a listpicker with object name in Windows phone?

The problem is that I have to fill out a ListPicker with the objects that I have saved in the database, but only with the object name. 问题是我必须用保存在数据库中的对象填写ListPicker,但只能使用对象名称。

I can populate the list using the ItemsSource property, but the list is being populated with the following " Traveler.Model.Car ", and I need the correct name of each object. 我可以使用ItemsSource属性填充列表,但是该列表使用以下“ Traveler.Model.Car ”填充,并且我需要每个对象的正确名称。

After that, still need to use their property, but this is easier. 之后,仍然需要使用其属性,但这更容易。

Xaml:
<toolkit:ListPicker Name="lpCars" ItemsSource="{Binding Items}"/>

 private void GetCarList()
        {            
            using (UtilsManagerDataBase getList = new UtilsManagerDataBase())
            {
                this._cars.Items = new ObservableCollection<Car>(getList.GetCarList());                
            }      
        }

Something like this would help. 这样的事情会有所帮助。

Make a listpicker like this in your xaml. 在您的xaml中进行这样的列表选择。

<toolkit:ListPicker Name="lstCars" VerticalAlignment="Top" Width="220" >
                <toolkit:ListPicker.ItemTemplate >
                    <DataTemplate >
                        <TextBlock Text="{Binding PropertyName}"/>
                    </DataTemplate>
                </toolkit:ListPicker.ItemTemplate>
                <toolkit:ListPicker.FullModeItemTemplate>
                    <DataTemplate >
                        <TextBlock Text="{Binding PropertyName}" FontSize="28"/>
                    </DataTemplate>
                </toolkit:ListPicker.FullModeItemTemplate>
            </toolkit:ListPicker>

an assign the list as an itemsource to the listpicker in c# like 一个将列表作为项源分配给c#中的listpicker

lstCars.ItemSource=Your List; lstCars.ItemSource =您的列表;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM