本文整理汇总了C#中Xamarin.Forms.Picker.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Picker.SetBinding方法的具体用法?C# Picker.SetBinding怎么用?C# Picker.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xamarin.Forms.Picker
的用法示例。
在下文中一共展示了Picker.SetBinding方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateOptionLayout
private ScrollView GenerateOptionLayout()
{
var stack = new StackLayout { Orientation = StackOrientation.Vertical };
var peak = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Peak" };
peak.SetBinding(Entry.TextProperty, OptionViewModel.PeakCommandPropertyName);
stack.Children.Add(peak);
var distance = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Distance" };
distance.SetBinding(Entry.TextProperty, OptionViewModel.DistanceCommandPropertyName);
stack.Children.Add(distance);
var dogAllowed = new Switch();
dogAllowed.SetBinding(Switch.IsToggledProperty, OptionViewModel.DogAllowedCommandPropertyName);
stack.Children.Add(dogAllowed);
var goodForKids = new Switch();
goodForKids.SetBinding(Switch.IsToggledProperty, OptionViewModel.GoodForKidsCommandPropertyName);
stack.Children.Add(goodForKids);
var seasonStart = new Picker { Title = "SeasonStart" };
foreach (var season in options.Seasons)
{
seasonStart.Items.Add(season.Value);
}
seasonStart.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonStartCommandPropertyName);
stack.Children.Add(seasonStart);
var seasonEnd = new Picker { Title = "SeasonEnd" };
foreach (var season in options.Seasons)
{
seasonEnd.Items.Add(season.Value);
}
seasonEnd.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonEndCommandPropertyName);
stack.Children.Add(seasonEnd);
var trailType = new Picker() { Title = "Trail Type" };
stack.Children.Add(trailType);
foreach (var type in options.TrailsTypes)
{
trailType.Items.Add(type.Value);
}
trailType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.TypeCommandPropertyName);
var trailDurationType = new Picker() { Title = "Trail Duration Type" };
foreach (var durType in options.TrailsDurationTypes)
{
trailDurationType.Items.Add(durType.Value);
}
trailDurationType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.DurationTypeCommandPropertyName);
stack.Children.Add(trailDurationType);
var button = GenericsContent.GenerateDefaultButton("Update");
button.SetBinding(Button.CommandProperty, OptionViewModel.UpdateCommandPropertyName);
stack.Children.Add(button);
return new ScrollView { Content = stack };
}
示例2: GeneratePickerForCommentRate
private static Picker GeneratePickerForCommentRate()
{
var picker = new Picker
{
TextColor = DefaultAppStyles.DefaultTextColor,
Title = "Rate",
};
for (int i = 0; i < 6; i++)
{
picker.Items.Add(i.ToString());
}
picker.SetBinding(Picker.SelectedIndexProperty, CommentsViewModel.RatePropertyName);
return picker;
}
示例3: BuildView
} //end ctor
private Layout BuildView()
{
this.BackgroundColor = AppColors.CONTENTLIGHTBKG;
Label lblItem = new Label() { Text = "Product:", TextColor = AppColors.LABELBLUE };
Picker pickerItem = new Picker() { HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = AppColors.LABELGRAY };
foreach(var a in Order.ItemTypes)
{
pickerItem.Items.Add(a);
}
pickerItem.SetBinding(Picker.SelectedIndexProperty, "ItemIndex");
Label lblPrice = new Label() { Text = "Price:", TextColor = AppColors.LABELBLUE };
Entry entryPrice = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand, Keyboard = Keyboard.Numeric,
BackgroundColor = AppColors.LABELGRAY };
entryPrice.SetBinding(Entry.TextProperty, "Price");
Label lblDateDue = new Label() { Text = "Date Due:", TextColor = AppColors.LABELBLUE };
DatePicker dateDue = new DatePicker() { HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = AppColors.LABELGRAY };
dateDue.SetBinding(DatePicker.DateProperty, "Order.DueDate");
Button btnOrder = new Button() { Text = "Place Order", HorizontalOptions = LayoutOptions.Center, TextColor = AppColors.LABELWHITE };
btnOrder.Clicked += btnOrder_Clicked;
StackLayout stack = new StackLayout()
{
Padding = 10,
Children =
{
lblItem,
pickerItem,
lblPrice,
entryPrice,
lblDateDue,
dateDue,
btnOrder
}
};
return stack;
}
示例4: SvgImageSamplePage
public SvgImageSamplePage ()
{
_ViewModel = new SvgImageSamplePageViewModel();
var insetLabel = new Label();
insetLabel.SetBinding(Label.TextProperty, nameof(SvgImageSamplePageViewModel.SvgInsets), stringFormat: "Stretchable Insets: {0:C2}");
var resourcePicker = new Picker() {
HorizontalOptions = LayoutOptions.FillAndExpand,
};
foreach (var resourceName in SvgImageSamplePageViewModel.AvailableResourceNames) {
resourcePicker.Items.Add(resourceName);
}
resourcePicker.SetBinding(Picker.SelectedIndexProperty, nameof(SvgImageSamplePageViewModel.SvgResourceIndex), BindingMode.TwoWay);
var insetSlider = new Slider() {
Minimum = 0,
Maximum = 35,
Value = _ViewModel.AllSidesInset,
};
insetSlider.SetBinding(Slider.ValueProperty, nameof(SvgImageSamplePageViewModel.AllSidesInset), BindingMode.TwoWay);
var slicingSvg = new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
WidthRequest = 300,
HeightRequest = 300,
};
slicingSvg.SetBinding(SvgImage.SvgStretchableInsetsProperty, nameof(SvgImageSamplePageViewModel.SvgInsets));
slicingSvg.SetBinding(SvgImage.SvgPathProperty, nameof(SvgImageSamplePageViewModel.SvgResourcePath));
var svgButton = new Button() {
WidthRequest = 300,
HeightRequest = 300,
BackgroundColor = Color.Transparent,
};
// The root page of your application
Title = "9-Slice SVG Scaling";
Content = new ScrollView {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Center,
Children = {
insetLabel,
resourcePicker,
insetSlider,
new AbsoluteLayout() {
WidthRequest = 300,
HeightRequest = 300,
Children = {
slicingSvg,
svgButton,
},
},
new Label () {
Text = "Using TwinTechsForms.SvgImage",
},
new Label () {
Text = "Proportional Scaling",
},
new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = "TwinTechs.TwinTechs.Example.SvgImageSample.Assets.funky-border.svg",
WidthRequest = 50,
HeightRequest = 50,
},
new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = "TwinTechs.TwinTechs.Example.SvgImageSample.Assets.funky-border.svg",
WidthRequest = 100,
HeightRequest = 100,
},
new Label () {
Text = "9-Slice Scaling",
},
new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = "TwinTechs.TwinTechs.Example.SvgImageSample.Assets.funky-border.svg",
SvgStretchableInsets = new ResizableSvgInsets (18),
WidthRequest = 50,
HeightRequest = 50,
HorizontalOptions = LayoutOptions.Start,
},
new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = "TwinTechs.TwinTechs.Example.SvgImageSample.Assets.funky-border.svg",
SvgStretchableInsets = new ResizableSvgInsets (18),
WidthRequest = 100,
HeightRequest = 100,
HorizontalOptions = LayoutOptions.Start,
},
new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = "TwinTechs.TwinTechs.Example.SvgImageSample.Assets.funky-border.svg",
SvgStretchableInsets = new ResizableSvgInsets (18),
WidthRequest = 300,
HeightRequest = 300,
HorizontalOptions = LayoutOptions.Start,
},
new Label () {
Text = "Using TwinTechsForms.NControl.SvgImageView",
},
new Label () {
Text = "Proportional Scaling",
},
//.........这里部分代码省略.........
示例5: TodoItemPage
public TodoItemPage()
{
this.SetBinding(ContentPage.TitleProperty, "Todo");
NavigationPage.SetHasNavigationBar(this, true);
//task name
var nameLabel = new Label { Text = "Name" };
var nameEntry = new Entry();
nameEntry.SetBinding(Entry.TextProperty, "Name");
//Notes
var notesLabel = new Label { Text = "Notes" };
var notesEntry = new Entry();
notesEntry.SetBinding(Entry.TextProperty, "Notes");
//Category
var categoryLabel = new Label { Text = "Category" };
var categoryPicker = new Picker
{
Title = "Category",
VerticalOptions = LayoutOptions.CenterAndExpand
};
foreach (var category in App.CategoryDatabase.GetCategories())
{
categoryPicker.Items.Add(category.Name);
}
categoryPicker.SetBinding(Picker.SelectedIndexProperty, "CategoryId");
//var categoryPicker = new BindablePicker
//{
// Title = "Category",
// VerticalOptions = LayoutOptions.CenterAndExpand,
// ItemsSource = App.CategoryDatabase.GetCategoryNames()
//};
//categoryPicker.SetBinding(BindablePicker.SelectedItemProperty, "Category");
//Due date
var dueDateLabel = new Label { Text = "Due Date" };
var dueDatePicker = new DatePicker
{
Format = "D",
VerticalOptions = LayoutOptions.CenterAndExpand
};
dueDatePicker.SetBinding(DatePicker.DateProperty, "DueDate");
//Reminder Date
var reminderDateLabel = new Label { Text = " Set Reminder" };
var reminderDatePicker = new DatePicker
{
Format = "D",
VerticalOptions = LayoutOptions.CenterAndExpand
};
reminderDatePicker.SetBinding(DatePicker.DateProperty, "ReminderDate");
//Done
var doneLabel = new Label { Text = "Done" };
var doneEntry = new Switch();
doneEntry.SetBinding(Switch.IsToggledProperty, "Done");
//Save
var saveButton = new Button { Text = "Save" };
saveButton.Clicked += (sender, e) =>
{
var todoItem = (TodoItem)BindingContext;
App.Database.SaveItem(todoItem);
this.Navigation.PopAsync();
};
Content = new StackLayout
{
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {
nameLabel, nameEntry,
notesLabel, notesEntry,
categoryLabel, categoryPicker,
dueDateLabel, dueDatePicker,
reminderDateLabel, reminderDatePicker,
doneLabel, doneEntry,
saveButton
}
};
}
示例6: App
public App() {
var resourcePicker = new Picker() {
VerticalOptions = LayoutOptions.CenterAndExpand,
};
foreach (var resourceName in TestModel.AvailableResourceNames) {
resourcePicker.Items.Add(resourceName);
}
resourcePicker.SetBinding(Picker.SelectedIndexProperty, nameof(TestModel.SvgResourceIndex), BindingMode.TwoWay);
var insetSlider = new Slider() {
Minimum = 0,
Maximum = 35,
Value = _ViewModel.AllSidesInset,
};
insetSlider.SetBinding(Slider.ValueProperty, nameof(TestModel.AllSidesInset), BindingMode.TwoWay);
var slicingSvg = new SvgImageView() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
SvgPath = _ViewModel.SvgResourcePath,
WidthRequest = 300,
HeightRequest = 300,
};
slicingSvg.SetBinding(SvgImageView.SvgStretchableInsetsProperty, nameof(TestModel.SvgInsets));
slicingSvg.SetBinding(SvgImageView.SvgPathProperty, nameof(TestModel.SvgResourcePath));
// The root page of your application
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children = {
resourcePicker,
insetSlider,
slicingSvg,
},
BindingContext = _ViewModel,
},
};
}
示例7: App
public App() {
_ViewModel = new TestModel();
var insetLabel = new Label();
insetLabel.SetBinding(Label.TextProperty, nameof(TestModel.SvgInsets), stringFormat: "Stretchable Insets: {0:C2}");
var resourcePicker = new Picker() {
HorizontalOptions = LayoutOptions.FillAndExpand,
};
foreach (var resourceName in TestModel.AvailableResourceNames) {
resourcePicker.Items.Add(resourceName);
}
resourcePicker.SetBinding(Picker.SelectedIndexProperty, nameof(TestModel.SvgResourceIndex), BindingMode.TwoWay);
var insetSlider = new Slider() {
Minimum = 0,
Maximum = 35,
Value = _ViewModel.AllSidesInset,
};
insetSlider.SetBinding(Slider.ValueProperty, nameof(TestModel.AllSidesInset), BindingMode.TwoWay);
var slicingSvg = new SvgImage() {
SvgAssembly = typeof(App).GetTypeInfo().Assembly,
WidthRequest = 300,
HeightRequest = 300,
};
slicingSvg.SetBinding(SvgImage.SvgStretchableInsetsProperty, nameof(TestModel.SvgInsets));
slicingSvg.SetBinding(SvgImage.SvgPathProperty, nameof(TestModel.SvgResourcePath));
var svgButton = new Button() {
WidthRequest = 300,
HeightRequest = 300,
};
// The root page of your application
MainPage = new NavigationPage (new ContentPage {
Title = "9-Slice SVG Scaling",
Content = new StackLayout {
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Center,
Children = {
insetLabel,
resourcePicker,
insetSlider,
new AbsoluteLayout() {
WidthRequest = 300,
HeightRequest = 300,
Children = {
slicingSvg,
svgButton,
},
},
},
BindingContext = _ViewModel,
},
});
svgButton.Clicked += (sender, e) => {
MainPage.DisplayAlert("Tapped!", "SVG button tapped!", "OK");
};
}
示例8: AddLocationPicker
private void AddLocationPicker()
{
var label = new Label
{
Text = c_cannotDetectGeolocationMessage,
};
layout.Children.Add(label);
var picker = new Picker
{
Title = "Province",
BindingContext = LoadingLocationViewModel.UserSelectedLocation,
};
layout.Children.Add(picker);
foreach (var location in LoadingLocationViewModel.RaffleLocations)
{
picker.Items.Add(location.Name);
}
picker.SetBinding(Picker.SelectedIndexProperty, new Binding("Name", BindingMode.TwoWay, new PickerRaffleLocationNameToIndexConverter(), LoadingLocationViewModel.RaffleLocations));
var button = new Button
{
Text = "Next",
};
layout.Children.Add(button);
button.Clicked += (sender, e) =>
{
MessagingCenter.Send<LoadingLocationPage>(this, "Success");
};
}
示例9: InitializeComponent
/// <summary>
/// Initializes the component.
/// </summary>
/// <param name="tshirt">Tshirt.</param>
void InitializeComponent(TShirt tshirt)
{
var layout = new StackLayout
{
VerticalOptions = LayoutOptions.Center
};
var image = new Image
{
HorizontalOptions = LayoutOptions.Center,
Source = tshirt.Image
};
var label = new Label { HorizontalOptions = LayoutOptions.Center, Text = tshirt.Name };
var genderCell = new SwitchCell { Text = "Women / Men" };
genderCell.SetBinding<OrderViewModel>(SwitchCell.OnProperty, vm => vm.IsMen);
var sizeLabel = new Label { Text = "Size", HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.Center };
var sizePicker = new Picker { Title = "Small", WidthRequest = 100.0, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Center };
sizePicker.Items.Add("Small");
sizePicker.Items.Add("Medium");
sizePicker.Items.Add("Large");
sizePicker.Items.Add("X-Large");
sizePicker.SetBinding<OrderViewModel>(Picker.SelectedIndexProperty, vm => vm.SizeIndex);
var sizeLayout = new StackLayout
{
Padding = new Thickness(15, 0),
Spacing = 0,
Orientation = StackOrientation.Horizontal,
Children =
{
sizeLabel,
sizePicker
}
};
var sizeCell = new ViewCell
{
View = sizeLayout
};
var optionSection = new TableSection { Title = "Options" };
optionSection.Add(genderCell);
optionSection.Add(sizeCell);
var tableView = new TableView
{
Intent = TableIntent.Form,
HeightRequest = 300.0,
Root = new TableRoot
{
optionSection
}
};
var buttonCancel = new Button { HorizontalOptions = LayoutOptions.EndAndExpand, Text = "Cancel" };
buttonCancel.Clicked += async (sender, e) => await Navigation.PopModalAsync();
var buttonOrder = new Button { HorizontalOptions = LayoutOptions.StartAndExpand, Text = "Purchase" };
buttonOrder.SetBinding<OrderViewModel>(Button.CommandProperty, vm => vm.OrderCommand);
var bottomLayout = new StackLayout
{
Spacing = 0,
Orientation = StackOrientation.Horizontal,
Children =
{
buttonCancel,
new Label
{
HorizontalOptions = LayoutOptions.CenterAndExpand
},
buttonOrder
}
};
layout.Children.Add(image);
layout.Children.Add(label);
layout.Children.Add(tableView);
layout.Children.Add(bottomLayout);
Content = layout;
}
示例10: CreatePickerFor
public static View CreatePickerFor(string propertyName, LayoutOptions layout)
{
Picker iiPicker = new Picker
{
HorizontalOptions = layout,
Title = "Leave Type",
HeightRequest = 150,
WidthRequest = 150,
};
iiPicker.Items.Add("Leave Type");
iiPicker.Items.Add("Casual Leave");
iiPicker.Items.Add("Medical Leave");
iiPicker.Items.Add("Paid Leave");
iiPicker.SetBinding(Picker.TitleProperty, propertyName);
iiPicker.SelectedIndex = 0;
return iiPicker;
}
示例11: RegistrationPage
public RegistrationPage(bool isUpdate, Page parent, UserAccount userAccount = null)
{
InitializeComponent();
if (!isUpdate)
{
Title = "Registration";
}
else
{
Title = "Update Information";
}
_tableView.Intent = TableIntent.Menu;
if (userAccount == null)
{
_viewModel = new AccountInfoViewModel();
}
else
{
_viewModel = new AccountInfoViewModel(userAccount);
}
this.BindingContext = _viewModel;
#region Birthday
var birthdayCell = new ViewCell();
_birthdaySection.Add(birthdayCell);
var birthdayLayout = new StackLayout
{
Padding = new Thickness(10, 0, 10, 0),
};
birthdayCell.View = birthdayLayout;
var datePicker = new DatePicker
{
Format = "MMM d yyyy",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
};
birthdayLayout.Children.Add(datePicker);
datePicker.SetBinding(DatePicker.DateProperty, "UserAccount.Birthday", BindingMode.TwoWay);
#endregion
#region Province
var provinceCellLayout = new StackLayout
{
Padding = new Thickness(10, 0, 10, 0),
};
_provinceCell.View = provinceCellLayout;
var provincePicker = new Picker
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
};
provinceCellLayout.Children.Add(provincePicker);
var firstCountry = DatabaseManager.DbConnection.Table<Country>().First();
var provinces = DatabaseManager.DbConnection.Table<Province>().Where(x => x.CountryCode == firstCountry.CountryCode).ToList();
foreach (var province in provinces)
{
provincePicker.Items.Add(province.ProvinceName);
}
provincePicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.Province", BindingMode.TwoWay, new PickerProvinceToIndexConverter(), provinces));
#endregion
#region Country
var countryCellLayout = new StackLayout
{
Padding = new Thickness(10, 0, 10, 0),
};
_countryCell.View = countryCellLayout;
var countryPicker = new Picker
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
};
countryCellLayout.Children.Add(countryPicker);
var countries = DatabaseManager.DbConnection.Table<Country>().ToList();
foreach (var country in countries)
{
countryPicker.Items.Add(country.CountryName);
}
countryPicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.Country", BindingMode.TwoWay, new PickerCountryToIndexConverter(), countries));
countryPicker.SelectedIndexChanged += (sender, e) =>
{
provincePicker.Items.Clear();
var countryCode = countries[countryPicker.SelectedIndex].CountryCode;
var newProvinces = DatabaseManager.DbConnection.Table<Province>().Where(x => x.CountryCode == countryCode).ToList();
// If there is no province, use N/A
if ((newProvinces == null) || (newProvinces.Count == 0))
{
newProvinces = new List<Province>
{
new Province
//.........这里部分代码省略.........