Ich arbeite an Cross-Plattform-Xamarin-Anwendung und ich möchte Hyperlink-Label für "Passwort vergessen?" auf der Anmeldeseite. Ich habe folgenden Code verwendet, um ein Label zu erstellen, aber ich weiß nicht, wie man ein onclick-Ereignis darauf erstellt.So erstellen Sie Click-Ereignis auf Etikett in Xamarin-Formulare dynamisch
MainPage = new ContentPage
{
BackgroundImage = "background.png",
Content = new StackLayout
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Spacing = 50,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
Text = "Welcome, Please Sign in!",
FontSize=50,
TextColor=Color.Gray,
},
new Entry
{
Placeholder="Username",
VerticalOptions = LayoutOptions.Center,
Keyboard = Keyboard.Text,
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 350,
HeightRequest = 50,
FontSize=20,
TextColor=Color.Gray,
PlaceholderColor=Color.Gray,
},
new Entry
{
Placeholder="Password",
VerticalOptions = LayoutOptions.Center,
Keyboard = Keyboard.Text,
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 350,
HeightRequest = 50,
FontSize=25,
TextColor=Color.Gray,
IsPassword=true,
PlaceholderColor =Color.Gray,
},
new Button
{
Text="Login",
FontSize=Device.GetNamedSize(NamedSize.Large,typeof(Button)),
HorizontalOptions=LayoutOptions.Center,
VerticalOptions=LayoutOptions.Fill,
WidthRequest=350,
TextColor=Color.Silver,
BackgroundColor=Color.Red,
BorderColor=Color.Red,
},
new Label //for this label I want to create click event to open new page
{
Text="Forgot Password?",
FontSize=20,
TextColor=Color.Blue,
HorizontalOptions=LayoutOptions.Center,
},
}
}
};
Sorry, aber dieser Code funktioniert nicht für mich, was könnte der Grund sein? 'lblLogin.GestureRecognizers.Add (neuer TapGestureRecognizer() {Command = neuer Befehl (() => {lblLogin_Clicked();});' 'private async void lblLogin_Clicked() {abwarten Navigation.PushAsync (new LoginPage())}} –
Was passiert, wenn Sie lblLogin async nicht machen? Oder machen Sie Ihren Befehl async und warten auf lblLogin? – noelicus