2016-09-22 86 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