Wie zu erstellen, klicken Sie auf Ereignis auf dem Etikett in xamarin forms dynamisch
Arbeite ich auf xamarin cross-Plattform-Anwendung, und ich will hyperlink erstellen label für "Passwort Vergessen?" auf login-Seite.
Ich habe folgende code Etiketten erstellen aber ich weiß nicht, wie erstelle onclick-Ereignis auf.
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,
},
}
}
};
InformationsquelleAutor Dipak | 2016-03-05
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen Sie dies :
Beispiel :
InformationsquelleAutor Vaikesh
Für Leute, die lieber mit XAML und wer wie zu bind-Befehl direkt an das ViewModel, können Sie diese verwenden:
InformationsquelleAutor Mik
lblLogin.GestureRecognizers.Add(new TapGestureRecognizer(){Command = new Command(() => {lblLogin_Clicked();})});
private async void lblLogin_Clicked(){await Navigation.PushAsync(new LoginPage());}
Was passiert, wenn Sie Sie nicht machen lblLogin async? Oder machen Sie Ihren Befehl "async" und "await" für lblLogin?
InformationsquelleAutor noelicus
Wenn es mehrere Orte mit anklickbaren Beschriftung, macht es Sinn, erstellen Sie ein Steuerelement, Erben von Xamarin.Formen Beschriften und nicht TapGestureRecognizer überall die Beschriftung erforderlich ist.
In der XAML-Datei, die Sie importieren den namespace, in dem das Steuerelement definiert ist, z.B.
Und verwenden Sie es als eine gewöhnliche Steuerung:
https://github.com/maxim-saplin/CrossPlatformDiskTest/blob/master/Saplin.CPDT.UICore/Controls/ExtendedLabel.cs
InformationsquelleAutor Maxim Saplin