Two fields in a Picker - Xamarin Forms

Asked

Viewed 127 times

0

It is possible to have 2 fields in a Picker? Today I have a Category listing and I would like to be able to put the Category Code in front.

inserir a descrição da imagem aqui

The XAML code of Picker:

               <Picker x:Name="pckCategoria"
                        Title="Selecione uma Categoria"
                        ItemDisplayBinding="{Binding CATEGORIA}"
                        FontSize="Small"
                        Margin="10, 0, 10, 0">
                </Picker>

If it is not possible to bring the two contents on picker I can simply receive the Category Code when a Category is selected too, it would already be an output, but so far I could not do, I’ve seen a lot of content but none could meet me.

2 answers

0


An option would be to create a property that merges the two contents, for example, the object would have three properties:
1-Code
2-Category
3-Categoriacode,
this last one would concatenate the two above, and then could give Binding in this last property.

Example:

XAML

<Picker x:Name="pckCategoria"
                        Title="Selecione uma Categoria"
                        ItemDisplayBinding="{Binding CategoriaCodigo}"
                        FontSize="Small"
                        Margin="10, 0, 10, 0">
                </Picker>

C#

Produto prod = new Produto();
prod.setCodigo(1);
prod.setCategoria("Alimento");
prod.setCategoriaCodigo(string.Format("{0} - {1}", prod.codigo, prod.categoria));
  • Could you give an example?

  • I added a very simple example to the answer.

-1

The Syncfusion platform has a Picker component with multiple values, I believe that’s exactly what you’re looking for. There is a free Syncfusion license for individual developers and small businesses.

https://www.syncfusion.com/products/xamarin/picker

  • We’re looking for native solutions, thank you. If it is not possible to bring the two contents in Picker I can simply receive the Category Code when a Category is selected as well, it would already be an output.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.