I created a list by code and I can not load the data. I made this list for xaml
and neither do I have another one that works ( xaml
) and I tried to do the same thing and nothing. When I upload the list it appears:
Autorizador.Model.ItensLib
Below the code
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPageItens : ContentPage
{
List<ItensLib> _data { get; set; }
int _idorcamento = 0;
List<ItensLib> itens;
DataService dataService = new DataService();
public int IdOrcamento { get; set; }
public MainPageItens()
{
InitializeComponent();
}
public MainPageItens(int idorcamento)
{
InitializeComponent();
this.IdOrcamento = idorcamento;
Task.Run(async () => await CarregaDados(IdOrcamento)).GetAwaiter().GetResult();
ListView lv = new ListView() { HasUnevenRows = true, SeparatorVisibility = SeparatorVisibility.None };
lv.ItemsSource = _data;
this.Content = lv;
}
async Task CarregaDados(int idorcamento)
{
try
{
_data = await dataService.GetItensLibAsync(idorcamento);
}
catch(Exception ex)
{
string erro = ex.Message;
}
}
private void listaItens_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
try
{
var libera = e.SelectedItem as Liberacao;
_idorcamento = libera.IdOrcamento;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private async void btnVoltar_Clicked(object sender, EventArgs e)
{
await Navigation.PopModalAsync(true);
}
private async void btnOk_Clicked(object sender, EventArgs e)
{
//
}
}
With xaml I do this:
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<StackLayout>
<Editor x:Name="edtMotivo" HeightRequest="40" InputTransparent="False">
</Editor>
</StackLayout>
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" Orientation="Horizontal">
<Button x:Name="btnOK" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" HeightRequest="40" Text="OK"
Clicked="btnOk_Clicked" FontSize="Small" BackgroundColor="Transparent" Image="" />
<Button x:Name="btnVoltar" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" HeightRequest="40" Text="Cancelar"
Clicked="btnVoltar_Clicked" FontSize="Small" BackgroundColor="Transparent" Image="editar.png" />
</StackLayout>
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" >
<ListView HasUnevenRows="True" x:Name="listaItens" ItemSelected="listaItens_ItemSelected" BackgroundColor="Aqua" SeparatorColor="Blue">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!--<ViewCell.ContextActions>
<MenuItem Clicked="OnAtualizar" CommandParameter="{Binding .}" Text="Atualizar" />
<MenuItem Clicked="OnDeletar" CommandParameter="{Binding .}" Text="Deletar" IsDestructive="True" />
</ViewCell.ContextActions>-->
<StackLayout Padding="10,10" Orientation="Horizontal" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
<Label Text="{Binding Produto}" HorizontalOptions="StartAndExpand" VerticalOptions="FillAndExpand" WidthRequest="270"/>
<Label Text="{Binding Qtde}" TextColor="Blue" HorizontalOptions="Center" WidthRequest="320"/>
<Label Text="{Binding UltCondicao}" HorizontalOptions="StartAndExpand" WidthRequest="520"/>
<Label Text="{Binding Unitario}" HorizontalOptions="StartAndExpand" WidthRequest="240"/>
<Label Text="{Binding Total}" HorizontalOptions="StartAndExpand" WidthRequest="240"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
</ContentPage.Content>
EDIT1 I was able to get the data, but the text was vertical. I did it for xaml. See the screenshot of my device and then my xaml?
Andmyxaml
<?xmlversion="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Autorizador.MainPageItens">
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" >
<ListView HasUnevenRows="True" x:Name="listaItens" ItemSelected="listaItens_ItemSelected" BackgroundColor="Aqua" SeparatorColor="Blue">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!--<ViewCell.ContextActions>
<MenuItem Clicked="OnAtualizar" CommandParameter="{Binding .}" Text="Atualizar" />
<MenuItem Clicked="OnDeletar" CommandParameter="{Binding .}" Text="Deletar" IsDestructive="True" />
</ViewCell.ContextActions>-->
<StackLayout Padding="10,10" Orientation="Horizontal" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
<Label Text="{Binding Produto}" HorizontalOptions="StartAndExpand" WidthRequest="270"/>
<Label Text="{Binding Qtde}" TextColor="Blue" HorizontalOptions="Center" WidthRequest="320"/>
<Label Text="{Binding UltCondicao}" HorizontalOptions="StartAndExpand" WidthRequest="520"/>
<Label Text="{Binding Unitario}" HorizontalOptions="StartAndExpand" WidthRequest="240"/>
<Label Text="{Binding Total}" HorizontalOptions="StartAndExpand" WidthRequest="240"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout>
<Editor x:Name="edtMotivo" HeightRequest="40" InputTransparent="False">
</Editor>
</StackLayout>
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" Orientation="Horizontal">
<Button x:Name="btnOK" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" HeightRequest="40" Text="OK"
Clicked="btnOk_Clicked" FontSize="Small" BackgroundColor="Transparent" Image="" />
<Button x:Name="btnVoltar" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" HeightRequest="40" Text="Cancelar"
Clicked="btnVoltar_Clicked" FontSize="Small" BackgroundColor="Transparent" Image="editar.png" />
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>