3
respostas

StackLayout para exibir Labels na vertical Xamarin

Boa tarde,

Atualmente estou desenvolvendo um App, e necessito empilhas as na vertical e não na horizontal como foi ministrado no curso - Aula 02 - Vídeo 3. Existe alguma forma de quebra de linha no XAML?

A organização deveria ficar exatamente assim:

DATA:  Fulano de Tal
DATA:  dd/mm/aaaa
ID: 500001
//Meu Código

            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Orientation="Horizontal">
                            <Label Text="NOME:" FontAttributes="Bold" VerticalOptions="Start"></Label>
                            <Label Text="{Binding nomePaciente}" VerticalOptions="Start"></Label>
                            <Label Text="DATA:" FontAttributes="Bold" VerticalOptions="Start"></Label>
                            <Label Text="11/10/2017" VerticalOptions="Start" HorizontalOptions="FillAndExpand"></Label>
                            <Label Text="PASSAGEM:" FontAttributes="Bold" VerticalOptions="Start"></Label>
                            <Label Text="{Binding passagem}" VerticalOptions="Start"></Label>
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
3 respostas

Olá, Everton!

Por padrão, o StackLayout trabalha na horizontal. Portanto, basta trocar esta linha:

<StackLayout Orientation="Horizontal">

por esta:

<StackLayout>

Boa sorte e bons estudos

Oi, Marcelo!

Mesmo removendo a Orientation="Horizontal"... A StackLayout não permite empilhar as Label, ou é algum comportamento da ViewCell. Exemplo: Numa mesma eu gostaria de exibir:

<Label Text="Nome"></Label> "Aqui seria algo similar a uma tag <br>"
<Label Text="Data"></Label> "Aqui seria algo similar a uma tag <br>"
<Label Text="IdPaciente"></Label>

Entendi, Everton. Acho que você poderia "quebrar" esse layout, mantendo uma listview com apenas as informações resumidas e, em vez de exibir tudo dentro de um ViewCell, exibir esses detalhes todos numa nova página de detalhes, utilizando o componente TableView, que também é explicado no curso:

https://cursos.alura.com.br/course/xamarin-aplicativos-mobile-com-visual-studio-parte-1/task/23774

Temos que tomar cuidado para não poluir demais a interface do usuário, e para isso acho que o TableView seria bem útil.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software