带有图像和文本的按钮以及图像下方的文本,如何? [英] Button with image and text and text bellow the image, how?

查看:43
本文介绍了带有图像和文本的按钮以及图像下方的文本,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次使用 xamarin 跨平台应用程序,我正在 Visual Studio 2017 社区中使用 xamarin 表单.

First time with cross-platform apps with xamarin, i'm working with xamarin forms in visual studio 2017 community.

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

I have a button with an image and text but the text needs to be below the image. currently the text is displaying to the left of the image, how can i do this?

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,
                }
            }
            }


        };
    }
}
}

推荐答案

您需要在按钮上使用 ContentLayout.

You need to use ContentLayout on your button.

这是我在 XAML 中使用的代码:

Here is the code I use in XAML:

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

顶部 = 图像的位置

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

0 = spacing between image & text

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

You should find easily how to use the ContentLayout in C#

这篇关于带有图像和文本的按钮以及图像下方的文本,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆