Преобразование в Xamarine
Такой вопрос: есть код в Xamarine, который проводит вычисления по нажатию кнопки и получает некоторое число в формате String, выводя его на экран. Как сделать так, чтобы это же число можно было подставлять в следующий метод, в котором он нужен для продолжения счета?
- Получение первого значения:
private void Button_Clicked_InfVol(object sender, EventArgs e)
{
double n1 = Convert.ToDouble(num1.Text);
int n3 = Convert.ToInt32(num3.Text);
result1.Text = (((n1 * 40 + 70) + (n1 * 8 * n3))).ToString();
}
Его xaml:
<Label Text="Calculator of Volume" Margin="5" FontSize="Large" FontAttributes="Bold"/>
<StackLayout Orientation="Vertical" Spacing="20" HorizontalOptions="Start">
<Entry x:Name="num1" WidthRequest="100" Keyboard="Numeric" Placeholder="kg"/>
<Entry x:Name="num3" WidthRequest="100" Keyboard="Numeric" Placeholder="%"/>
</StackLayout>
<Label x:Name="result1" HorizontalTextAlignment="Center" TextColor="Black"/>
<Button Text="Calculate" Clicked="Button_Clicked_InfVol"/>
- Код, где нужен результат виде числа:
private void Button_Clicked_InfSpeed(object sender1, EventArgs s)
{
try
{
double n2 = Convert.ToDouble(num2.Text);
result2.Text = ((result1 /2) / n2).ToString();
}
catch (Exception exc)
{
DisplayAlert("Error", exc.ToString(), "Ok");
};
И его xaml:
<Label Text="Calculator of Speed" Margin="5" FontSize="Large" FontAttributes="Bold"/>
<Label Text="50% вводится за 6-12 часов" Margin="20,0,0,0"/>
<StackLayout Orientation="Vertical" Spacing="10" HorizontalOptions="Start">
<Entry x:Name="num2" WidthRequest="100" Keyboard="Numeric" Placeholder="hour"/>
</StackLayout>
<Label x:Name="result2" HorizontalTextAlignment="Center" Margin="5"/>
<Button Text="Calculate" Clicked="Button_Clicked_InfSpeed"/>