简体   繁体   中英

Xamarin.Forms: Button in TabbedPage

How to add button to other page on this code (this is part of one card in TabbedPage):

this.Children.Add(new ContentPage
        {
            Title = "Text",
            Content = new StackLayout
            {
                Padding = 20,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    new Image
                    {
                        Source = ImageSource.FromFile("image.png")
                    },
                    new Label
                    {
                        TextColor = Color.FromHex("#5F5A5A"),
                        FontSize = 16,
                        Text = "Other text"  
                    }
             }
            }
        });

Thanks for help.

If I understood your issue right, you just need button in another tab?

this.Children.Add(new ContentPage
        {
            Title = "Text",
            Content = new StackLayout
            {
                Padding = 20,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    new Image
                    {
                        Source = ImageSource.FromFile("image.png")
                    },
                    new Label
                    {
                        TextColor = Color.FromHex("#5F5A5A"),
                        FontSize = 16,
                        Text = "Other text"  
                    }
             }
            }
        });
this.Children.Add(new ContentPage
        {
            Title = "Button",
            Content = new StackLayout
            {
Children ={
              new Button{
Image = ImageSource.FromFile("button.png"),
Backgroundcolor = "Transparent"

}
             }
            }
        });

Alternatively you can use tap gesture recognizer

var button = new Image {  }; 
button.GestureRecognizers.Add (new TapGestureRecognizer (sender => {

}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM