2016-09-22 83 views
0

如何添加按钮,其他页面上该代码(这是一个TabbedPage卡的一部分):Xamarin.Forms:巴顿在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" 
        } 
      } 
      } 
     }); 

感谢您的帮助。

回答

0
Is 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" 

} 
      } 
      } 
     }); 

替代地可以使用敲击手势识别

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

})); 
+0

确定,但如何添加图像作为按钮的按钮 – user5734658

+0

只需设置图像属性,以所希望的图象和背景颜色为透明的。请参阅编辑 – Greensy

+0

第一个代码不工作/ ImageSource.FromFile不能隐含在xamarin.forms – user5734658