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

Смежные вопросы