How to fill a button with an image in Xamarin Forms?

后端 未结 2 1059
再見小時候
再見小時候 2021-01-31 19:32

I am trying to fill a Button with an Image. The button resides within a Grid. The problem is that the image is not fully filling the button. I have als

相关标签:
2条回答
  • 2021-01-31 20:26

    I have not used it myself but maybe you can use this one from XLab

    https://github.com/XLabs/Xamarin-Forms-Labs/wiki/ImageButton

    0 讨论(0)
  • 2021-01-31 20:35

    Try to place an image instead of button.

    You can make use of Tap Gesture Gesture Recognizer to take click events.

    Try something like this :

    <Image Source="tapped.jpg">
        <Image.GestureRecognizers>
            <TapGestureRecognizer
                    Tapped="OnTapGestureRecognizerTapped"  />
      </Image.GestureRecognizers>
    </Image>
    

    The code for the event handler

    void OnTapGestureRecognizerTapped(object sender, EventArgs args) {
        var imageSender = (Image)sender;
        // Do something
        DisplayAlert ("Alert", "Tap gesture recoganised", "OK");
    }
    

    Refer : Adding a Tap Gesture Gesture Recognizer

    0 讨论(0)
提交回复
热议问题