首页 > 解决方案 > 按钮图标不显示 xamarins 表单 xaml

问题描述

我是 xaml 的新手,我有一个问题。我正在尝试在 xamarin.forms 中的文本旁边创建一个带有图标的按钮。但是当我试图显示它时,我的应用程序上什么都没有。添加 png 图标。图像位于Ressources->drawable文件夹中。这是 xaml 代码。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="epicture.MainPage">

    <StackLayout>
        <Button Text="Log in" ImageSource="login.png" Clicked="Button_Clicked" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" BackgroundColor="#00c851" TextColor="White"></Button>
        <WebView Navigating="WebView_Navigating"></WebView>
    </StackLayout>
</ContentPage>

标签: xamlxamarinxamarin.forms

解决方案


我也面临同样的问题 ImageButton 没有文本属性。因此,我创建了带有文本属性的自定义 ImageButton 控件,您可以参考这可能会对您有所帮助。

https://xamarincodingtutorial.blogspot.com/2019/05/step-to-create-imagebutton-with-text.html


推荐阅读