Rene Sá
Rene Sá

Reputation: 4

ListPicker Binding Items - Selected Item

In my Windows Phone app, I have a ListPicker. This ListPicker is populated from a collection. The data is loaded correctly, but the text is wrongly displayed. I do not know why... Follow the images for understanding (the error is red marked):

XAML:

<toolkit:ListPicker x:Name="Picker" ExpansionMode="FullScreenOnly"
                    Visibility="Collapsed"
                    FullModeHeader="Selecione o vendedor:"
                    ItemsSource="{Binding funcionarioVendedor}"
                     Margin="135,186,35,313" BorderBrush="Black">
                    <toolkit:ListPicker.FullModeItemTemplate>
                        <DataTemplate>
                            <TextBlock Margin="0,20" Text="{Binding nome}"/>
                        </DataTemplate>
                    </toolkit:ListPicker.FullModeItemTemplate>
                </toolkit:ListPicker>

C#:

public ObservableCollection<vendedores> funcionarioVendedor { get; set; }

    public class vendedores
    {
        public string nome { get; set; }
    }

var myData = e.Result;

            var reader = new StringReader(myData);
            text = reader.ReadToEnd();
            // String JSON
            string json = text;

            // Parse JObject
            JArray jObj = JArray.Parse(json);

            funcionarioVendedor = new ObservableCollection<vendedores>(
 jObj.Children().Select(jo => jo.ToObject<vendedores>()));

            Picker.ItemsSource = funcionarioVendedor;

Upvotes: 0

Views: 472

Answers (2)

yasen
yasen

Reputation: 3580

The problem is that you're only setting the FullModeItemTemplate. The template used for the selected item is the one specified with the ItemTemplate property, so you have to set it as well.

Upvotes: 1

Kulasangar
Kulasangar

Reputation: 9434

Within your `ItemsSource="{Binding funcionarioVendedor}", try adding this too:

 ItemsSource="{Binding funcionarioVendedor, ElementName=this}"

Reference: WP8 ListPicker Bind

Binding ListPicker to Data

Upvotes: 0

Related Questions