question

LloydSheen-3317 avatar image
0 Votes"
LloydSheen-3317 asked WenyanZhang-MSFT commented

Xamarin Picker does not work

OK after about 5 hours of trying everything to get a Dropdown list in Xamarin I have to concede defeat.

I have a list of years that I want to "pick" from. I have tried the following:

  1. Used Grid/StackLayout to host the Picker control. No difference (tried this because a post said that was his problem.

  2. Tried List and ObservableCollection as the property containing the years (again because someone said that solves the problem) but it didn't.

  3. Used XAML to indicate binding of ItemsSource and used c# code to set the property.

The basic results of every experiment was that I get a line. Yes a line. That is all , there is no dropdown, no list , actually nothing useful.

I really cannot understand why a dropdown list seems to be such a lost item for Xamaring.

HELP.....




dotnet-xamarin
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I changed the list to a list of an class with an int property. After that I could see that the property that was in the ItemDisplayBinding was access for each instance of the class but still nothing shows in the UI.

Really need help to solve this or is it just the Picker that needs to be fixed?

0 Votes 0 ·

You could try to examine the control in Live Visual Tree & Live Property Explorer and check if UI match the properties actually on the control, but you said the binding was access for each instance, I will recommend you to check if there are any errors listed in binding diagnostics: https://docs.microsoft.com/en-us/visualstudio/xaml-tools/xaml-data-binding-diagnostics?view=vs-2022.
If you want to display the item, it should be String not int, refer to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/picker/populating-itemssource

And I'm not sure which platform you are testing on, you said you only get a line, it seems on Android, but it's only my guess. Would you mind sharing some code snippets or more information so that I can test?


0 Votes 0 ·

Ok I have tried some of things you mentioned in your post.

First is the Live Visual Tree. Well that is a complete failure. I use it and it shows almost nothing. I have what I am looking at in a ContentView. In the Visual Tree this content view does not appear. There is a binding error which again is not understandable so I created a simple label which is bound to the same BindingContext as the ItemsSource of the dropdown and it shows in the UI so the BindingContext is correct.

I then created a Label in the ContentView and bound it to the Count of the items in the ItemsSource. It shows correctly.

Yes I am using Android and I have tried this with both the Android emulator and my phone (G21) and both have the same problem.

I have tried a bunch of different "collection" controls and none of them will display the collection I am binding to their ItemsSource.

Very confused.

0 Votes 0 ·

There is a binding error which again is not understandable

The binding error is the key point, would you mind sharing it with me? From your description, you could check each item in your collection, you said they are of type Int, try to change them to String. It's easier to help you if you provide some snippets about your collection( ItemsSource ), your page and other binding logic. You also could share a basic minimal reproducible sample with me, try to upload it to GitHub and attach the link here.

0 Votes 0 ·

0 Answers