Button does not appear in the App

Asked

Viewed 28 times

-1

I made a button, listview. The listview is working because I started it, but how do I do with button? Below my code:

protected override async void OnAppearing()
        {
            base.OnAppearing();

            //Task.Run(async () => await CarregaDados(IdOrcamento)).GetAwaiter().GetResult();
            await CarregaDados(IdOrcamento);

            Entry ent = new Entry
            {
                Placeholder = "Motivo"
            };


            Button btnOk = new Button
            {
                Text = "Aprovar",
                BackgroundColor = Color.Gold,
                Font = Font.Default,
                FontSize = 10,
                TextColor = Color.Green,
                HeightRequest = 35,
                WidthRequest = 80
            };

            Button btnCancel = new Button
            {
                Text = "Negar",
                BackgroundColor = Color.Gold,
                Font = Font.Default,
                FontSize = 10,
                TextColor = Color.Green,
                HeightRequest = 35,
                WidthRequest = 80
            };

            Button btnVoltar = new Button
            {
                Text = "Voltar",
                BackgroundColor = Color.Gold,
                Font = Font.Default,
                FontSize = 10,
                TextColor = Color.Red,
                HeightRequest = 35,
                WidthRequest = 80
            };

            btnVoltar.Clicked += Voltar;


            ListView lv = new ListView()
            {
                HasUnevenRows = true,
                SeparatorVisibility = SeparatorVisibility.Default,
                BackgroundColor = Color.White,
                SeparatorColor = Color.Gold,
                SelectedItem = "lv_ItemSelected",
                WidthRequest = 240,
                HeightRequest = 180
            };


            lv.ItemsSource = _data;

            lv.ItemTemplate = new DataTemplate(typeof(ListItemCell));
            lv.ItemTemplate.SetBinding(TextCell.TextProperty, "Produto");
            lv.ItemTemplate.SetBinding(TextCell.DetailProperty, "DadosItens");

            this.Content = lv;

        }

        private static void Voltar(object sender, EventArgs e)
        {

        }

1 answer

0

I solved it. In Onappearing I created a new instance of Stacklayout and put the buttons, entry, listview and returned this stacklayout. It worked. Something like that:

StackLayout stack = new StackLayout()
            {
                Children = { ent, btnOk, btnCancel, btnVoltar, lv }
            };

            this.Content = stack;

Browser other questions tagged

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