【问题标题】:Button image Xamarin.forms按钮图像 Xamarin.forms
【发布时间】:2018-11-21 10:14:10
【问题描述】:

Image Source="icons.png" 工作正常 但是当我插入此代码时:Button Image="icons.png" 该应用程序不会在 Xamarin live 中显示

这是我的代码:

 <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="Project.CustomImages">
        <StackLayout>
        <Button Image="icons.png"/>
        <Label Text="TEST"/>
            <Image Source="icons.png"/>
        </StackLayout>
    </ContentPage>

这是Recources/drawable的截图: Screenshot

【问题讨论】:

标签: image button xamarin.forms


【解决方案1】:

尝试放置图像而不是按钮。

您可以使用 Tap Gesture Recognizer 来获取点击事件。

试试这样的:

<Image Source="icons.jpg">
    <Image.GestureRecognizers>
        <TapGestureRecognizer
                Tapped="OnTapped"  />
  </Image.GestureRecognizers>
</Image>

事件处理程序的代码

void OnTapped(object sender, EventArgs args) {
    // Do something
    DisplayAlert ("Alert", "Image Button Clicked", "OK");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多