Hello friends. In this article, we will get a picture click feature with Xamarin Forms. There’s actually a very simple way of doing this.
First you come to the design screen and here you are first controlling an image. Which picture or position does not matter at all. After you give us the design features you want to control the image, we need to assign a TapGestureRecognizer between the GestureRecognizers properties. With this feature, this function will work when the image is touched once. If you do not build it, Visual Studio will automatically create the functions for you, but the variables that you will get from the outside are as below.
<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ResmeTiklama" x:Class="ResmeTiklama.MainPage"> <StackLayout> <!-- Place new controls here --> <Image Source="fenerbahce.png" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="200" HeightRequest="200"> <Image.GestureRecognizers> <TapGestureRecognizer Tapped="tiklandi"/> </Image.GestureRecognizers> </Image> </StackLayout> </ContentPage>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; namespace ResmeTiklama { public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } // Tıklnadığnda oluşacakların metodu private void tiklandi(object sender,EventArgs e) { DisplayAlert("Başarılı", "Fotoğrafa tıklandı...", "OK"); } } }
What I’m trying to do here is giving a message to the screen where the photo is touched. So it seems that the photo is touched. You can customize it for your own projects. If you have any questions, please feel free to mail or comment me.
Leave a Reply