こんにちは、これは初めてXamarinを使用しています。私がしようとしているのは、このアプリケーションをListViewを使用するように変更することですが、最初にステッパーから値を取得してラベルに印刷する方法を学びたいと思います。Stepper Xamarin.formからラベルに値を送信
私はmovieamountがステッパーから選択した値を送信してtotalLabelテキストに送信することは知っていますが、すでにラベル0にラベルを送信し、選択した値を変更する方法はわかりません。選択された正しい量が返されますが、決して画面に印刷されません。 "強引な" 方法 -
public static string movieamount;
public static string pickmovie;
public static string paymentSelected;
public static string dateSelected;
public static string timeSelected;
public static string totalLabel;
public MainPage()
{
Picker picker = new Picker
{
Title = "Movies",
VerticalOptions = LayoutOptions.CenterAndExpand
};
var options = new List<string> { "Kill Bill", "Matrix", "Zombieland", "The Dark Knight", "Terminator", "Apocalypse Now", "Resouvoir dogs", "Horrible Bosses", "The Breakup", "Wedding Crashers", };
picker.SelectedIndexChanged += (sender, e) =>
{
pickmovie = picker.Items[picker.SelectedIndex];
};
foreach (string optionName in options) picker.Items.Add(optionName);
//listView.ItemTapped += async (sender, e) => { await DisplayAlert("Tapped", e.Item.ToString() + " was selected.", "OK"); ((ListView)sender).SelectedItem = null; };
//this.Content = listView;
Label valuelabel = new Label
{
Text = "0",
FontAttributes = FontAttributes.Bold,
FontSize = 30,
HorizontalOptions = LayoutOptions.Center
};
Stepper stepper = new Stepper
{
Minimum = 0,
Maximum = 10,
Increment = 1,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
stepper.ValueChanged += (sender, e)=>
{
movieamount = stepper.Value.ToString();
};
Picker payment = new Picker
{
Title = "Payment Method",
VerticalOptions = LayoutOptions.CenterAndExpand
};
var options1 = new List<string> {"Visa", "MasterCard", "AmericanExpress", "Free",};
foreach (string optionName in options1) payment.Items.Add(optionName);
payment.SelectedIndexChanged += (sender, e) =>
{
paymentSelected = payment.Items[payment.SelectedIndex];
};
//TimePicker was here
Label totalLabel = new Label
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
FontSize = 40,
FontAttributes = FontAttributes.Bold | FontAttributes.Italic
};
DatePicker datePicker = new DatePicker
{
Format = "D",
VerticalOptions = LayoutOptions.CenterAndExpand,
};
//---Handle Inline---
datePicker.DateSelected += (object sender, DateChangedEventArgs e) =>
{
//eventValue.Text = e.NewDate.ToString();
dateSelected = e.NewDate.ToString();
};
TimePicker timePicker = new TimePicker
{
Format = "T",
VerticalOptions = LayoutOptions.CenterAndExpand
};
// set inline handler
timePicker.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == TimePicker.TimeProperty.PropertyName)
{
timeSelected = timePicker.Time.ToString();
};
};
Button button = new Button
{
Text = "Submit",
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.Fill
};
button.Clicked += (sender, args) =>
{
totalLabel.Text = "You have ordered " + movieamount + " " +
pickmovie + " \n You will be paying with " + paymentSelected + " " +
"Your delivery will be delivered at " + dateSelected + " " + timeSelected;
};
StackLayout stackLayout = new StackLayout
{
Children =
{
picker,
payment,
valuelabel,
stepper,
datePicker,
totalLabel,
timePicker,
button,
}
};
BackgroundColor = Color.Yellow;
this.Content = stackLayout;
}
}
}