简体   繁体   English

如何在xamarin crossplatform中单击按钮获取另一页面中滑块的值

[英]how to get the value of slider in another page with a button click in xamarin crossplatform

I am new in Xamarin and I want to go to another screen from one screen. 我是Xamarin的新手,我想从一个屏幕进入另一个屏幕。 Here i have Two sliders, 2 labels and a button. 这里我有两个滑块,2个标签和一个按钮。 I want to open another screen after clicking on that button and I should display the values of two sliders in another xaml page.. like slider1 = 2.5 slider2=4. 我想在点击该按钮后打开另一个屏幕,我应该在另一个xaml页面中显示两个滑块的值..比如slider1 = 2.5 slider2 = 4。 How can i do this? 我怎样才能做到这一点?

my cs code: 我的cs代码:

public partial class MainPage : ContentPage

{

    public MainPage()

    {

        InitializeComponent();

    }

  private void MainSlider1_OnValueChanged(object o, ValueChangedEventArgs e)

    {

        Double slider1 = MainSlider1.Value + 1;

        MainLabel1.Text = Convert.ToString(slider1);

    }

 private void MainSlider2_OnValueChanged(object o, ValueChangedEventArgs e)

    {

        Double slider2 = MainSlider2.Value + 1;

        MainLabel2.Text = Convert.ToString(slider2);

    }

    private async void NavigateButton_OnClicked(object o, EventArgs e)

    {

        await Navigation.PushAsync(new Page1());

}

You can pass the parameters by having a class as below: 您可以通过如下所示传递参数:

private async void NavigateButton_OnClicked(object o, EventArgs e)
{  
    var yourClass = new YourClass {
      Slider1Text = MainLabel1.Text,
      Slider2Text = MainLabel2.Text
    };

    await Navigation.PushAsync (new Page1(yourClass));
}

For this we have to change in the Constructor method of Page1: 为此,我们必须在Page1的Constructor方法中进行更改:

public Page1(YourClass yourClass)
{

}

And you can use the data from YourClass as required. 您可以根据需要使用YourClass中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM