当前位置: 首页>>代码示例>>C#>>正文


C# Switch.SetBinding方法代码示例

本文整理汇总了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;
        }
开发者ID:patsy02,项目名称:KompetansetorgetXamarin,代码行数:30,代码来源:CustomSwitchCell.cs

示例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 ();
		}
开发者ID:patridge,项目名称:demos-xamarin.forms-tour,代码行数:27,代码来源:X.FPluginDemo.cs

示例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
				}
			};
		}
开发者ID:DIGIHOME-MK,项目名称:Xamarin-forms-winrt,代码行数:58,代码来源:TodoItemPage.cs

示例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
                    }
            };
        }
开发者ID:DavidStrickland0,项目名称:Xamarin-Forms-Samples,代码行数:16,代码来源:NoXAMLDirectBinding.cs

示例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,
                }
            };
        }
开发者ID:zcccust,项目名称:Study,代码行数:46,代码来源:TestPage.cs

示例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}
			};

		}
开发者ID:JeffHarms,项目名称:xamarin-forms-samples-1,代码行数:42,代码来源:TodoItemPage.cs

示例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 }
			};
		}
开发者ID:felipecembranelli,项目名称:MyXamarinSamples,代码行数:41,代码来源:EmployeeView.cs

示例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);
            }
        }
开发者ID:modulexcite,项目名称:Altostratus,代码行数:40,代码来源:ConfigurationPage.xaml.cs

示例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
                    }
            };
        }
开发者ID:DavidStrickland0,项目名称:Xamarin-Forms-Samples,代码行数:22,代码来源:NoXAMLNoBinding.cs

示例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;
		}
开发者ID:jdluzen,项目名称:Xamarin-Forms-Labs,代码行数:41,代码来源:NfcDevicePage.cs

示例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
				}
			};
		}
开发者ID:RickySan65,项目名称:xamarin-forms-samples,代码行数:37,代码来源:TodoItemPageCS.cs

示例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
                }
            };
        }
开发者ID:SindhoojaMullapudi,项目名称:UDo,代码行数:82,代码来源:TodoItemPage.cs

示例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
                }
            };
        }
开发者ID:ZaK14120,项目名称:xamarin-forms-samples,代码行数:81,代码来源:TodoItemPage.cs

示例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
				}
			};
		}
开发者ID:RickySan65,项目名称:xamarin-forms-samples,代码行数:75,代码来源:TodoItemPage.cs

示例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
                }
            };
        }
开发者ID:zcccust,项目名称:Study,代码行数:68,代码来源:SaveByVMCS.cs


注:本文中的Switch.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。