本文整理汇总了C#中Switch.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Switch.SetBinding方法的具体用法?C# Switch.SetBinding怎么用?C# Switch.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Switch
的用法示例。
在下文中一共展示了Switch.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomSwitchCell
//public static BindableProperty nameProperty = BindableProperty.Create<CustomSwitchCell, Thickness>(d => d.Padding, default(Thickness));
//public static BindableProperty toggleProperty = BindableProperty.Create<CustomSwitchCell, Thickness>(d => d.Padding, default(Thickness));
public CustomSwitchCell()
{
var stack = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Padding = new Thickness(30, 0, 30, 5),
Spacing = 0
};
var NameLabel = new Label();
NameLabel.HorizontalOptions = LayoutOptions.FillAndExpand;
NameLabel.VerticalOptions = LayoutOptions.CenterAndExpand;
NameLabel.FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label));
NameLabel.LineBreakMode = LineBreakMode.NoWrap;
NameLabel.TextColor = Color.Black;
NameLabel.SetBinding(Label.TextProperty, "Name");
stack.Children.Add(NameLabel);
var ToggleSwitch = new Switch();
ToggleSwitch.HorizontalOptions = LayoutOptions.End;
ToggleSwitch.VerticalOptions = LayoutOptions.CenterAndExpand;
ToggleSwitch.SetBinding(Switch.IsToggledProperty, "IsSelected");
stack.Children.Add(ToggleSwitch);
View = stack;
}
示例2: App
public App ()
{
var stringSettingEntry = new Entry ();
stringSettingEntry.SetBinding (Entry.TextProperty, nameof (SettingsViewModel.SomeStringSetting));
var boolSettingSwitch = new Switch ();
boolSettingSwitch.SetBinding (Switch.IsToggledProperty, nameof (SettingsViewModel.SomeBoolSetting));
// The root page of your application
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
Text = "Some String"
},
stringSettingEntry,
new Label {
Text = "Some Bool"
},
boolSettingSwitch,
}
}
};
MainPage.BindingContext = new SettingsViewModel ();
}
示例3: TodoItemPage
public TodoItemPage ()
{
//this.SetBinding (ContentPage.TitleProperty, "Name");
this.Title = "Add Todo item";
NavigationPage.SetHasNavigationBar (this, true);
var nameLabel = new Label { Text = "Name" };
var nameEntry = new Entry ();
nameEntry.SetBinding (Entry.TextProperty, "Name");
var notesLabel = new Label { Text = "Notes" };
var notesEntry = new Entry ();
notesEntry.SetBinding (Entry.TextProperty, "Notes");
var doneLabel = new Label { Text = "Done" };
var doneEntry = new Switch ();
doneEntry.SetBinding (Switch.IsToggledProperty, "Done");
var saveButton = new Button { Text = "Save" };
saveButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.SaveItem(todoItem);
this.Navigation.PopAsync();
};
var deleteButton = new Button { Text = "Delete" };
deleteButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.DeleteItem(todoItem.ID);
this.Navigation.PopAsync();
};
var cancelButton = new Button { Text = "Cancel" };
cancelButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
this.Navigation.PopAsync();
};
var speakButton = new Button { Text = "Speak" };
speakButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
};
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {
nameLabel, nameEntry,
notesLabel, notesEntry,
doneLabel, doneEntry,
saveButton, deleteButton, cancelButton,
speakButton
}
};
}
示例4: NoXAMLDirectBinding
public NoXAMLDirectBinding()
{
this.BindingContext = new SmartViewModel ();
Image img = new Image ();
img.SetBinding<SmartViewModel> (Image.SourceProperty,dvm=>dvm.ImagePath);
Switch switchView = new Switch();
switchView.SetBinding<DumbViewModel> (Switch.IsToggledProperty,dvm=>dvm.BoolOnOff);
this.Content = new StackLayout {
Children = {
img,
switchView
}
};
}
示例5: TestPage
public TestPage()
{
this.BindingContext = new TestPageViewModel();
var ed = new Editor { Text = "BindingTo TextValue" };
ed.SetBinding(Editor.TextProperty, "TextValue", mode: BindingMode.OneWayToSource);
var lb = new Label { Text = "" };
lb.SetBinding(Label.TextProperty, "TextValue");
var sw = new Switch();
sw.SetBinding(Switch.IsToggledProperty, "BoolValue", mode: BindingMode.TwoWay);
var sc = new SwitchCell { Text = "BindingTo BoolValue" };
sc.SetBinding(SwitchCell.OnProperty, "BoolValue", mode: BindingMode.TwoWay);
var tc = new TextCell { Text = "" };
tc.SetBinding(TextCell.TextProperty, "BoolValue", stringFormat:"Value: {0}");
var tv = new TableView
{
Intent = TableIntent.Settings,
Root = new TableRoot
{
new TableSection("TableView")
{
sc,
tc,
},
}
};
Content = new StackLayout
{
Padding = 20,
Children = {
new Label {
Text = "INotifyPropertyChanged Test",
FontSize = 30,
},
ed,
lb,
sw,
tv,
}
};
}
示例6: TodoItemPage
public TodoItemPage ()
{
this.SetBinding (ContentPage.TitleProperty, "Name");
NavigationPage.SetHasNavigationBar (this, true);
var nameLabel = new Label { Text = "Name" };
var nameEntry = new Entry { Text = "<new>" };
nameEntry.SetBinding (Entry.TextProperty, "Name");
var notesLabel = new Label { Text = "Notes" };
var notesEntry = new Entry ();
notesEntry.SetBinding (Entry.TextProperty, "Notes");
var doneLabel = new Label { Text = "Done" };
var doneEntry = new Switch ();
doneEntry.SetBinding (Switch.IsToggledProperty, "Done");
var saveButton = new Button { Text = "Save" };
saveButton.SetBinding (Button.CommandProperty, "SaveCommand");
var cancelButton = new Button { Text = "Cancel" };
cancelButton.SetBinding (Button.CommandProperty, "CancelCommand");
cancelButton.SetBinding (Button.IsVisibleProperty, "CanCancel");
var deleteButton = new Button { Text = "Delete" };
deleteButton.SetBinding (Button.CommandProperty, "DeleteCommand");
deleteButton.SetBinding (Button.IsVisibleProperty, "CanDelete");
var speakButton = new Button { Text = "Speak" };
speakButton.SetBinding (Button.CommandProperty, "SpeakCommand");
speakButton.SetBinding (Button.IsVisibleProperty, "CanSpeak");
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {nameLabel, nameEntry,
notesLabel, notesEntry,
doneLabel, doneEntry,
saveButton, cancelButton, deleteButton, speakButton}
};
}
示例7: EmployeeView
public EmployeeView ()
{
photo = new Image { WidthRequest = IMAGE_SIZE, HeightRequest = IMAGE_SIZE };
photo.SetBinding (Image.SourceProperty, "DetailsPlaceholder.jpg");
favoriteLabel = new Label ();
favoriteSwitch = new Switch ();
favoriteSwitch.SetBinding (Switch.IsToggledProperty, "Person.IsFavorite");
personName = new Label {
XAlign = TextAlignment.Center,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
FontAttributes = FontAttributes.Bold,
IsVisible = Device.OS == TargetPlatform.WinPhone
};
var optionsView = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Orientation = StackOrientation.Vertical,
Children = { favoriteLabel, favoriteSwitch }
};
var headerView = new StackLayout {
Padding = new Thickness (10, 20, 10, 0),
HorizontalOptions = LayoutOptions.StartAndExpand,
Orientation = StackOrientation.Horizontal,
Children = { photo, optionsView }
};
var listView = new ListView { IsGroupingEnabled = true };
listView.ItemSelected += OnItemSelected;
listView.SetBinding (ListView.ItemsSourceProperty, "PropertyGroups");
listView.GroupHeaderTemplate = new DataTemplate (typeof(GroupHeaderTemplate));
listView.ItemTemplate = new DataTemplate (typeof(DetailsItemTemplate));
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Children = { personName, headerView, listView }
};
}
示例8: CreateCategorySwitches
private void CreateCategorySwitches()
{
StackLayout sl;
Switch sw;
Label lb;
// Build the children of the ScrollView.StackPanel from the Categories list, XAML is as follows
// except that we want to set the binding for each switch to an individual category:
// <StackLayout Padding="20, 15, 10, 5" Orientation ="Horizontal">
// <Switch IsToggled="{ Binding IsActive, Mode=TwoWay }" />
// <Label Text="{ Binding Name }" FontSize="Large" YAlign="Center" />
// </StackLayout>
foreach (Category c in viewModel.Categories)
{
sl = new StackLayout();
sl.Padding = new Thickness(20, 15, 10, 5);
sl.Orientation = StackOrientation.Horizontal;
sw = new Switch();
sw.BindingContext = c;
sw.SetBinding(Switch.IsToggledProperty, "IsActive", BindingMode.TwoWay);
sl.Children.Add(sw);
// NOTE: There seems to be a bug on Android, filed as https://bugzilla.xamarin.com/show_bug.cgi?id=27798.
// When going back to the home page from here, the Home.OnAppearing event is raised before Configuration.OnDisappearing,
// and thus a call to viewModel.CheckChanges there happens too late for Home.OnAppearing to make use of it.
// The workaround is to watch UI interaction and keep updating our change state which is inefficient, but works.
sw.Toggled += SwitchToggled;
lb = new Label();
lb.BindingContext = c;
lb.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label));
lb.YAlign = TextAlignment.Center;
lb.SetBinding(Label.TextProperty, "Name", BindingMode.OneWay);
sl.Children.Add(lb);
optionsStack.Children.Add(sl);
}
}
示例9: NoXAMLNoBinding
public NoXAMLNoBinding()
{
this.BindingContext = new DumbViewModel ();
Image img = new Image{Source="icon.png"};
((DumbViewModel)this.BindingContext).PropertyChanged += (sender, e) => {
if (((DumbViewModel)sender).BoolOnOff)
img.Source = "icon.png";
else
img.Source = "noci.png";
};
Switch switchView = new Switch();
switchView.SetBinding<DumbViewModel> (Switch.IsToggledProperty,dvm=>dvm.BoolOnOff);
this.Content = new StackLayout {
Children = {
img,
switchView
}
};
}
示例10: NfcDevicePage
/// <summary>
/// Initializes a new instance of the <see cref="NfcDevicePage"/> class.
/// </summary>
public NfcDevicePage()
{
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
_device = DependencyService.Get<INfcDevice>();
var stack = new StackLayout();
if (_device == null || !_device.IsEnabled)
{
stack.Children.Add(new Label()
{
TextColor = Color.Red,
Text = "No NFC support",
});
}
else
{
stack.Children.Add(new Label()
{
Text = "Connection state",
});
var s = new Switch()
{
IsEnabled = false,
HorizontalOptions = LayoutOptions.FillAndExpand
};
s.SetBinding(Switch.IsToggledProperty, "Connected");
s.BindingContext = this;
stack.Children.Add(s);
}
Content = stack;
}
示例11: TodoItemPageCS
public TodoItemPageCS(bool isNew = false)
{
isNewItem = isNew;
var nameEntry = new Entry { Placeholder = "task name" };
nameEntry.SetBinding(Entry.TextProperty, "Name");
var notesEntry = new Entry();
notesEntry.SetBinding(Entry.TextProperty, "Notes");
var doneSwitch = new Switch();
doneSwitch.SetBinding(Switch.IsToggledProperty, "Done");
var saveButton = new Button { Text = "Save" };
saveButton.Clicked += OnSaveActivated;
var deleteButton = new Button { Text = "Delete" };
deleteButton.Clicked += OnDeleteActivated;
var cancelButton = new Button { Text = "Cancel" };
cancelButton.Clicked += OnCancelActivated;
Title = "Todo Item";
Content = new StackLayout
{
VerticalOptions = LayoutOptions.StartAndExpand,
Children = {
new Label { Text = "Name" },
nameEntry,
new Label { Text = "Notes" },
notesEntry,
new Label { Text = "Done" },
doneSwitch,
saveButton,
deleteButton,
cancelButton
}
};
}
示例12: 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
}
};
}
示例13: TodoItemPage
public TodoItemPage()
{
this.SetBinding (ContentPage.TitleProperty, "Name");
NavigationPage.SetHasNavigationBar (this, true);
var nameLabel = new Label { Text = "Name" };
var nameEntry = new Entry { StyleId = "TodoName", Placeholder="Todo action" };
nameEntry.SetBinding (Entry.TextProperty, "Name");
var notesLabel = new Label { Text = "Notes" };
var notesEntry = new Entry { StyleId = "TodoNotes", Placeholder = "More info" };
notesEntry.SetBinding (Entry.TextProperty, "Notes");
var doneLabel = new Label { Text = "Done" };
var doneEntry = new Switch { StyleId = "TodoDone" };
doneEntry.SetBinding (Switch.IsToggledProperty, "Done");
AccessibilityEffect.SetInAccessibleTree(nameLabel, false);
AccessibilityEffect.SetAccessibilityHint(nameEntry, "Todo name");
AccessibilityEffect.SetInAccessibleTree(notesLabel, false);
AccessibilityEffect.SetAccessibilityHint(notesEntry, "Additional notes");
AccessibilityEffect.SetInAccessibleTree(doneLabel, false);
AccessibilityEffect.SetAccessibilityLabel (doneEntry, "whether todo item is done");
var saveButton = new Button { Text = "Save",
BackgroundColor = Color.Green,
BorderRadius = 0,
TextColor = Color.White,
StyleId = "TodoSave"
};
saveButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.SaveItem(todoItem);
this.Navigation.PopAsync();
};
var deleteButton = new Button { Text = "Delete",
BackgroundColor = Color.Red,
BorderRadius = 0,
TextColor = Color.White,
StyleId = "TodoDelete"
};
deleteButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.DeleteItem(todoItem.ID);
this.Navigation.PopAsync();
};
var cancelButton = new Button { Text = "Cancel",
BackgroundColor = Color.Gray,
BorderRadius = 0,
TextColor = Color.White,
StyleId = "TodoCancel"
};
cancelButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
this.Navigation.PopAsync();
};
var speakButton = new Button { Text = "Speak", StyleId = "TodoSpeak"};
speakButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
};
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {
nameLabel, nameEntry,
notesLabel, notesEntry,
doneLabel, doneEntry,
saveButton, deleteButton, cancelButton,
speakButton
}
};
}
示例14: TodoItemPage
public TodoItemPage ()
{
this.SetBinding (ContentPage.TitleProperty, "Name");
NavigationPage.SetHasNavigationBar (this, true);
var nameLabel = new Label (); // no Text! localized later
var nameEntry = new Entry ();
nameEntry.SetBinding (Entry.TextProperty, "Name");
var notesLabel = new Label (); // no Text! localized later
var notesEntry = new Entry ();
notesEntry.SetBinding (Entry.TextProperty, "Notes");
var doneLabel = new Label (); // no Text! localized later
var doneEntry = new Switch ();
doneEntry.SetBinding (Switch.IsToggledProperty, "Done");
var saveButton = new Button (); // no Text! localized later
saveButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.SaveItem(todoItem);
this.Navigation.PopAsync();
};
var deleteButton = new Button (); // no Text! localized later
deleteButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
App.Database.DeleteItem(todoItem.ID);
this.Navigation.PopAsync();
};
var cancelButton = new Button (); // no Text! localized later
cancelButton.Clicked += (sender, e) => {
this.Navigation.PopAsync();
};
var speakButton = new Button (); // no Text! localized later
speakButton.Clicked += (sender, e) => {
var todoItem = (TodoItem)BindingContext;
DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
};
// TODO: Forms Localized text using two different methods:
// refer to the codebehind for AppResources.resx.designer
nameLabel.Text = AppResources.NameLabel;
notesLabel.Text = AppResources.NotesLabel;
doneLabel.Text = AppResources.DoneLabel;
// using ResourceManager
saveButton.Text = AppResources.SaveButton;
deleteButton.Text = L10n.Localize ("DeleteButton", "Delete");
cancelButton.Text = L10n.Localize ("CancelButton", "Cancel");
speakButton.Text = L10n.Localize ("SpeakButton", "Speak");
// HACK: included as a 'test' for localizing the picker
// currently not saved to database
//var dueDateLabel = new Label { Text = "Due" };
//var dueDatePicker = new DatePicker ();
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {
nameLabel, nameEntry,
notesLabel, notesEntry,
doneLabel, doneEntry,
//dueDateLabel, dueDatePicker,
saveButton, deleteButton, cancelButton, speakButton
}
};
}
示例15: SaveByVMCS
public SaveByVMCS()
{
BindingContext = vm;
var labelStyle = new Style(typeof(Label))
{
Setters = {
new Setter { Property = Label.XAlignProperty, Value = TextAlignment.End },
new Setter { Property = Label.YAlignProperty, Value = TextAlignment.Center },
new Setter { Property = Label.WidthRequestProperty, Value = 150 }
}
};
var labelName = new Label { Text = "Name:", Style = labelStyle };
entryName = new Entry { Placeholder = "Input your name", HorizontalOptions = LayoutOptions.FillAndExpand };
entryName.SetBinding(Entry.TextProperty, "Name", mode: BindingMode.TwoWay);
var labelBirthday = new Label { Text = "Birthday:", Style = labelStyle };
var pickerBirthday = new DatePicker { };
pickerBirthday.SetBinding(DatePicker.DateProperty, "Birthday", mode: BindingMode.TwoWay);
var labelLike = new Label { Text = "Like Xamarin?", Style = labelStyle };
var switchLike = new Switch { };
switchLike.SetBinding(Switch.IsToggledProperty, "Like", mode: BindingMode.TwoWay);
var saveButton = new Button { Text = "Save", HorizontalOptions = LayoutOptions.FillAndExpand };
saveButton.Clicked += saveButton_Clicked;
var loadButton = new Button { Text = "Load", HorizontalOptions = LayoutOptions.FillAndExpand };
loadButton.Clicked += loadButton_Clicked;
var clearButton = new Button { Text = "Clear", HorizontalOptions = LayoutOptions.FillAndExpand };
clearButton.Clicked += clearButton_Clicked;
resultLabel = new Label { Text = "", FontSize = 30 };
Title = "Save to dic by vm (C#)";
Content = new StackLayout
{
Padding = 10,
Spacing = 10,
Children = {
new Label { Text = "DataSave Sample", FontSize = 40, HorizontalOptions = LayoutOptions.Center },
new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
labelName, entryName
}
},
new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
labelBirthday, pickerBirthday
}
},
new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
labelLike, switchLike
}
},
new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
saveButton, loadButton, clearButton
}
},
resultLabel
}
};
}