XAML
<DataTemplate x:Name="PickTmplItemTipo">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding tipo}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Name="PickTmplFullTipo">
<StackPanel Orientation="Horizontal" Margin="0,25,0,0">
<TextBlock Name="lblTipo" Width="350" Text="{Binding tipo}" FontFamily="{StaticResource PhoneFontFamilyLight}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
</StackPanel>
</DataTemplate>
<toolkit:ListPicker
Grid.Row="0"
ItemsSource="{Binding}" Margin="21,0,22,0"
Header="{Binding Source={StaticResource LocalizedStrings}, Path=Localizedresources.strTipoUni}"
FullModeHeader="{Binding Source={StaticResource LocalizedStrings}, Path=Localizedresources.strTipoUni}"
FullModeItemTemplate="{Binding Source={StaticResource PickTmplFullTipo}}"
ItemTemplate="{Binding Source={StaticResource PickTmplItemTipo}}"
Name="lPickTipo"
TabIndex="0"
Height="98"
VerticalAlignment="Top"
ExpansionMode="FullScreenOnly"
Tap="lPickTipo_Tap"
SelectionChanged="lPickTipo_SelectionChanged" />
C#
Fill listpicker:
List<tipos> _lstTipos { get; set; }
private void cargaLista()
{
using (serviciosDBDataContext miDataContext = new serviciosDBDataContext(conn))
{
_lstTipos = miDataContext.tipos.ToList();
}
this.lPickTipo.ItemsSource = _lstTipos;
}
Set selecteditem:
if I try this, returns this error "SelectedItem must always be set to a valid value."
this.lPickTipo.SelectedItem = myStringValue;
And if I try the next thing, returns null error:
this.lPickTipo.SelectedItem = lPickTipo.Items.First(x => (x as ListPickerItem).Content.ToString() == myStringValue);
But I can not to set by selectindex because I dont know which index equival