Saturday, 4 November 2017

Xamarin Forms Label Clicked Event [Tutorial 43]


Step1:Page1.cs
public partial class Page1 : ContentPage
{
Label labelSuggestion;
public Page1()
{
InitializeComponent();
labelSuggestion = new Label()
{
Text = "Please Click US",
IsVisible = true,
TextColor = Color.Black,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
BackgroundColor = Color.Green,
};
Content = labelSuggestion;
this.Content = new StackLayout
{
Children =
{
labelSuggestion
}
};
labelSuggestion.GestureRecognizers.Add(new TapGestureRecognizer((view) => OnLabelClicked()));
}
//private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
// {
// await Navigation.PushAsync(new Page2());
// }
private async void OnLabelClicked()
{
//var url = "https://docs.google.com/forms/d/e/1FAIpQLSdGn31o21N1s8ixMPqfSmtk07SHiL-FJCCm10kK6enrsZwpbw/viewform";
//Device.OpenUri(new Uri(url));
await Navigation.PushAsync(new Page2());
}
}
}
view raw page1.cs hosted with ❤ by GitHub
Step2:
<!--<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="This is Label Clicked Event"
VerticalOptions="Center"
HorizontalOptions="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="TapGestureRecognizer_Tapped"
/>
</Label.GestureRecognizers>
</Label>
</StackLayout>-->
view raw page1.xaml hosted with ❤ by GitHub
Step3: Holaaa!!! Tutorial Completes

No comments:

Post a Comment