Considéreme un desarrollador de aplicaciones muy principiante que no ha desarrollado nada hasta ahora :) Me gusta "número" x2 (multiplicar por 2) aparece delante del "resultado" después de hacer clic en el botón "Cálculo". Además, ¿cómo puedo mostrar el resultado en otra página / pantalla? aquí hay una foto de la aplicación ingrese la descripción de la imagen aquí
Aquí está mi código: MainPage.xaml
<StackLayout>
<Label
Text="Give me a number"
Margin="0,50,0,0" Padding="13,0,0,0"/>
<Entry Placeholder="number"
x:Name="numb"
Keyboard="Numeric"
Margin="130,-30,40,0"
Opacity="1" Rotation="0"
TranslationX="16" />
<Button Text=" Calculate "
BackgroundColor="#F6DEDE"
FontSize="Large"
FontAttributes="Bold"
/>
<Label
Text=" Result "
FontSize="30"
Margin="0, 20, 0, 0"
Padding="10,0,0,0"/>
</StackLayout>
Aquí está MainPage.xaml.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Test
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
void CalculateClicked(object sender, EventArgs args)
{
float numb = float.Parse(this.numb.Text);
float B = 100 * numb * 2;
// show B in front of result or on another page
}
}
}
3 respuestas
Como las dos respuestas ya señalan, debe dar un nombre a la etiqueta en xaml y luego puede usarlo en el código de atrás para establecer el texto.
void CalculateClicked(object sender, EventArgs args)
{
float numb = float.Parse(this.numb.Text);
float B = 100 * numb * 2;
// show B in front of result or on another page
resultLabel.Text = B.ToString();
}
Otra cosa que debe hacer es agregar un evento de clic al botón y asignarle CalculateClicked
. Luego, cuando haga clic en el botón, se activará el método CalculateClicked
:
<Button Text=" Calculate "
BackgroundColor="#F6DEDE"
FontSize="Large"
FontAttributes="Bold"
Clicked="CalculateClicked"
/>
Primero, dale un nombre a tu etiqueta
<Label x:Name="result"
Text=" Result "
FontSize="30"
Margin="0, 20, 0, 0"
Padding="10,0,0,0"/>
Ahora, debe configurar el resultado en la etiqueta
void CalculateClicked(object sender, EventArgs args)
{
float numb = float.Parse(this.numb.Text);
float B = 100 * numb * 2;
result.Text = $": {B}";
}
Primero, dale un nombre a tu Label
<Label x:Name="lblResult"
Text=" Result "
FontSize="30"
Margin="0, 20, 0, 0"
Padding="10,0,0,0"/>
Entonces puedes asignarle un valor del código
void CalculateClicked(object sender, EventArgs args)
{
float numb = float.Parse(this.numb.Text);
float B = 100 * numb * 2;
// show B in front of result or on another page
lblResult.Text += ": " + B.ToString();
}
Nuevas preguntas
xamarin
Xamarin es una plataforma que consta de Xamarin.iOS, Xamarin.Android, Xamarin.Mac y Xamarin Test Cloud. Le permite escribir aplicaciones nativas multiplataforma para iOS, Android y Mac y seguir su aplicación durante todo su ciclo de vida. La introducción de Xamarin.Forms admite el desarrollo nativo de IU para iOS, Android y Windows