Question

I m struggling in setting the Value in List Picker to be the one I want.

I have that in xaml

DataTemplate x:Key="ListPickerED">
    <Grid HorizontalAlignment="Stretch" Width ="420">
<TextBlock
Text="{Binding Company}" 
FontSize="{StaticResource PhoneFontSizeMedium}" 
Grid.Column="0" Grid.ColumnSpan="1" 
VerticalAlignment="Top" Margin ="0, 12, 0, 0"/>


</Grid >
</DataTemplate >
<toolkit:ListPicker x:Name="CompanyListPicker" 
CacheMode="BitmapCache" 
ItemsSource="{Binding AllMyCompanies}"
ItemTemplate="{StaticResource ListPickerED }"
Margin ="9,267,12,26">
</toolkit:ListPicker>"

The listpicker is properly populated , no problem with that.

My problem when I navigate to the page, I would like the ListPicker to have the value passed by the navigation highlighted.

If NavigationContext.QueryString.TryGetValue("BridgeCompany_Param", bridgeCompany_Msg) Then CompanyListPicker.SelectedItem = bridgeCompany_Msg End If

That doesn't work .

Any help would be appreciated.

Thank you.

Was it helpful?

Solution

After a while I found the answer

I first converted the collection to be a list , and I was able to do :

CompanyListPicker.SelectedItem = Company_Msg

but then I faced some other issue, as this is used to associate a foreign key.

So after some more trials , I decided to go back to the collection , as I had no problem with the foreign key.

And now it works , below is the code use to load a page and select in the picklist the item which is given as parameter.

It might not be the most beautiful code , but it works.

the idea is to parse all the items in the collection, it is possible to access them by a variable (i), when the value is found (Trouve) , I keep that index number and I assign it to listPicker.selectedIndex.

 If NavigationContext.QueryString.TryGetValue("BridgeCompany_Param", bridgeCompany_Msg) Then
Dim i, Trouve As Integer
i = 0
Trouve = 0
While i < App.ViewModel.AllMyCompanies.Count
If (App.ViewModel.AllMyCompanies.Item(i).Company = bridgeCompany_Msg) Then
Trouve = i
End If
i = i + 1
End While
CompanyListPicker.SelectedIndex = Trouve
End If

hopefully that my help someone else, unless that was too obvious for everybody ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top