Search code examples
c#windows-phone-8bindingwindows-phonelistpicker

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;

Solution

  • 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.