2017-07-08 84 views
0

第一次与xamarin交叉平台的应用程序,我正在使用视觉工作室2017社区xamarin形式。按钮与图像和文字和文字以下图像,如何?

我有一个图片和文字按钮,但文字需要在图片下方。当前文本显示在图像的左侧,我该怎么做?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Xamarin.Forms; 

namespace AppUnap 
{ 
public class PPrincipal : ContentPage 
{ 
    public PPrincipal() 
    { 
     Button btn1= new Button(); 
     btn1.Image = "notas.png"; 
     btn1.Text = "Calificaciones"; 
     btn1.HorizontalOptions = LayoutOptions.CenterAndExpand; 

     Button btn2 = new Button(); 
     btn2.Image = "notas.png"; 
     btn2.Text = "Aula Virtual"; 
     btn2.HorizontalOptions = LayoutOptions.CenterAndExpand; 

     Content = new StackLayout 
     { 
      Spacing = 0, 
      VerticalOptions = LayoutOptions.CenterAndExpand, 
      Children = 
      { 
      new StackLayout 
      { 
       Spacing = 0, 
       Orientation = StackOrientation.Horizontal, 
       Children = 
       {      
        btn1, 
        btn2, 
       } 
      } 
      } 


     }; 
    } 
} 
} 

回答

2

您需要在按钮上使用ContentLayout。

这是我在XAML中使用代码:

<Button Command="{Binding MyCommand}" ContentLayout="Top,0" Text="mytext" Image="myimage.png" /> 

顶值=图像的位置

0 =图像&文字之间的间距

你应该很容易找到如何使用ContentLayout在C#