Image Button in Xamarin forms - xamarin

I am very new to Xamarin. I need to add a image button that display Facebook icon on my Xamarin app and when the user clicks on that icon, I need to be redirected to http://www.facebook.com. How can I accomplish this. Here is what I have so far
<StackLayout Padding="50">
<Image Source="facebook.png" HeightRequest="80" WidthRequest="80" >
<Button Text="Mission" Clicked="Mission_Clicked"></Button>
<Button Text="Continue" Clicked="Continue_Clicked"></Button>
</StackLayout>
On the click of Facebook, I just want the Facebook page to be displayed on the phones.
Any help will be appreciated.

Button already has an Image property
<Button Clicked="FacebookClicked" Image="facebook.png" HeightRequest="80" WidthRequest="80" />
UPDATE Xamarin.Forms 3.4.0
ImageButton:
The ImageButton view combines the Button view and Image view to create a button whose content is an image.
<ImageButton Source="xamagon.png"
BackgroundColor="Transparent"
WidthRequest="300"
HeightRequest="300"
FlexLayout.AlignSelf="Center"
FlexLayout.Grow="1"
Clicked="ImageButton_Clicked"
Aspect="AspectFit">
</ImageButton>

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 :

Related

syncfusion xamarin form button control, click event not fired on IOS simulator but fired on my IPHONE

I am using syncfusion xamarin form button control on my project, the click event didn't fire on the IOS simulator but fired on both my IPHONE and IPAD. anyone experienced this issue?
the XMAL is attached below,
<buttons:SfButton Padding="10"
x:Name="btnCamera"
Grid.Column="1"
IsCheckable="False"
BackgroundColor="White"
BorderColor="Transparent"
BorderWidth="0"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Clicked="btnCamera_Clicked"
HasShadow="True"
CornerRadius="20">
<buttons:SfButton.Content>
<Image Source="Camera.png"
HeightRequest="45"
WidthRequest="45"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</buttons:SfButton.Content>
</buttons:SfButton>
<buttons:SfButton Padding="10"
x:Name="btnImageFolder"
Grid.Column="3"
IsCheckable="False"
BackgroundColor="White"
BorderColor="Transparent"
BorderWidth="0"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Clicked="btnImageFolder_Clicked"
HasShadow="True"
CornerRadius="20">
<buttons:SfButton.Content>
<Image Source="ImageFolder.png"
HeightRequest="45"
WidthRequest="45"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</buttons:SfButton.Content>
</buttons:SfButton>
Query: StackOverflow : syncfusion xamarin form button control, click event not fired on IOS simulator but fired on my IPHONE
We are unable to replicate the reported issue on our side. We are prepared a sample based on the provided code snippet since the ButtonClick event is properly called on our side. We have prepared a sample and video for your reference. Sample
Please make sure you have added SfButtonRenderer for iOS in the AppDelagates.cs file. Refer to the below link,
Link: https://help.syncfusion.com/xamarin/button/gettingstarted#additional-step-for-ios
Please check and let us know once the problem was resolved on your side.
Regards,
Ruba Shanmugam

Get user click event as each image in android gallery is selected

I'm using this awesome tutorial for xamarin forms in order to get multiple images from gallery on android devices: https://www.xamboy.com/2019/03/12/select-multiple-images-and-videos-in-xamarin-forms/
Everything is working fine. I wonder if there's a way, on code implementation for Android, to intercept when user click on each image.
Right now there is just method for OnActivityResult. Any idea?
Maybe use something like that:
<Image>
<Image.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="MyMethodThatFiresWhenImageIsTapped"/>
</Image.GestureRecognizers>
</Image>

Nativescript-vue: How to build a chat template

I want to build a small chat as we all know from WhatsApp.
Currently I am able to display messages within a ListView.
<template>
<Page>
<ListView separatorColor="transparent" for="item in messages">
<v-template>
<GridLayout>
<TextView
height="auto"
editable="false"
:text="item.message"
/>
</GridLayout>
</v-template>
</ListView>
</Page>
</template>
My next step is to add a TextView with a Button at the end of the page. But here are coming my problems:
Which Layout component should I choose to position a TextView at the bottom of the page.
If I tab into my editable TextView the virtual keyboard overlaps my current page. Instead it should resize the whole page. How can I do this?
This is my current playground project: https://play.nativescript.org/?template=play-vue&id=F8lXkO
EDIT:
I found a way which works on Android using DockLayout:
https://play.nativescript.org/?template=play-vue&id=F8lXkO&v=3
Unfortunately this works only in the playground. Using the latest nativescript version on android is not working. If I tab on the TextView the layout breaks => https://github.com/sowinski/nativescript-vue-chat
Use GridLayout for the entire view. You can use this as a guide - https://github.com/Especializa/nativescript-whatsapp-template
Use this to better understand Nativescript layouts - https://www.nslayouts.com/

Xamarin Forms: How to give exact circle background for icons?

I have some icons on my xamarin forms project. I need a circle background for my icon. See the screenshot below:
I tried Xam.Plugins.Forms.ImageCircle plugin and tried Framelayout. Imagecircle plugin only cropping the icon and Framelayout gives a rounded corner layout. Nothing gives me a perfect circle background. I go through the FFImageloading documentation, but which is also the same as Imagecircle plugin.
Image code
<Image
Source="ic_group_fill_xx.png"
WidthRequest="25"
HeightRequest="25"/>
Is there any way to achieve this feature?
I usually prefer to make an icon that by default has a circle in it, doesn't make sense to add extra code for something that can be done for free.
There is great document by Android on working with Images for Android applications which can be found here, you can also use Android Asset Studio for creating awesome images.
I normally use an ImageButton for this (and because of the clicked property you don't need to use Gesture Recognizers for detecting taps)
The code below gives me a perfect circle on Android & iOS
<ImageButton Source="icon_name"
BackgroundColor="Blue"
HeightRequest="60"
WidthRequest="60"
CornerRadius="30"
Padding="15"
Clicked="Btn_Clicked" />
The image below is from my app, the image button is inside AbsoluteLayout and the icon is 64x64
Use the ImageCircle.Forms.Plugn plugin which I am already using it,
Import namespace like below,
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
And use the image control like below sample,
<controls:CircleImage
Source="{Binding ProfileImage}"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="40"
Aspect="AspectFill"
BorderColor="#B8BCC9"
BorderThickness="1"
HeightRequest="40" />

WP7: Button Tap event not firing, why?

I'm using WP7 'Mango' SDK and Phone Toolkit for my app. I have a control, which contains ExpanderView. I'm using next template for ExpanderView's header:
<toolkit:ExpanderView.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"/>
<Button Tap="ShowMoreTap">
<Button.Template>
<ControlTemplate>
<TextBlock Text="show more..."/>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</DataTemplate>
</toolkit:ExpanderView.HeaderTemplate>
The code behind:
private void ShowMoreTap(object sender, System.Windows.Input.GestureEventArgs e)
{
// Some logic here
}
I don't want to expand/collapse the ExpanderView when user taps on the button, I need some specific actions there. The problem is that ShowMoreTap event is never fired.
Any ideas?
Thanks
According to the source code the Tap is handled by the ExpanderView to cause the expansion (or collapse)
Apparently this event then never bubbles up; it is not a routed event.
I see two options:
using the source code from codeplex make a customized version of the ExpanderView or
stop using the ExpanderView because you do not want to expand anything. You could probably switch to another control that you style similarly more easily. Remember: do not use a control because it looks the way you want it, use it because it has the properties and behavior you need. WP7 allows you to style any control.

Resources