简体   繁体   English

Xamarin.Forms:TabbedPage中的按钮

[英]Xamarin.Forms: Button in TabbedPage

How to add button to other page on this code (this is part of one card in TabbedPage): 如何在此代码上将按钮添加到其他页面(这是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 => {

}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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