public MainPage() { InitializeComponent(); MessageLabel.SetBinding(Button.TextProperty, "ChangeText", BindingMode.OneWayToSource); MessageButton.SetBinding(Button.CommandProperty, "ButtonCommand"); }
public MainPage() { InitializeComponent(); MessageLabel.BindingContext = ToggleSwitch; MessageLabel.SetBinding(Label.IsVisibleProperty, "IsToggled", BindingMode.TwoWay); MessageButton.BindingContext = ToggleSwitch; MessageButton.SetBinding(Button.IsEnabledProperty, "IsToggled", BindingMode.TwoWay); }
public MainPage() { InitializeComponent(); ToggleSwitch.BindingContext = DataModel; MessageButton.BindingContext = DataModel; MessageLabel.BindingContext = DataModel; ToggleSwitch.SetBinding(Switch.IsToggledProperty, "IsTrue", BindingMode.OneWayToSource); MessageButton.SetBinding(Button.IsEnabledProperty, "IsTrue", BindingMode.OneWay); MessageLabel.SetBinding(Label.IsVisibleProperty, "IsTrue", BindingMode.OneWay); MessageLabel.SetBinding(Label.TextProperty, "CurrentSaying", BindingMode.OneWay); }
public ValidatableEntryControl() { Control.BindingContext = this; Control.SetBinding(Entry.TextProperty, "EntryText"); Children.Add(Control); MessageLabel.SetBinding(VisualElement.IsVisibleProperty, "IsInValid"); MessageLabel.SetBinding(Label.TextProperty, "Message"); MessageLabel.BindingContext = this; MessageLabel.TextColor = Color.Red; Children.Add(MessageLabel); }
public MainPage() { InitializeComponent(); //BindingContext is the same for all elements, so can use the containing view //ToggleSwitch.BindingContext = ViewModel; //MessageButton.BindingContext = ViewModel; //MessageLabel.BindingContext = ViewModel; BindingContext = ViewModel; ToggleSwitch.SetBinding(Switch.IsToggledProperty, "UIVisible", BindingMode.OneWayToSource); MessageButton.SetBinding(Button.TextProperty, "SayingNumber", BindingMode.OneWay, null, "Saying: {0:d}"); MessageButton.SetBinding(Button.CommandProperty, "ButtonCommand"); MessageLabel.SetBinding(Label.TextProperty, "CurrentSaying", BindingMode.OneWay); MessageLabel.SetBinding(Label.IsVisibleProperty, "UIVisible", BindingMode.OneWay); MessageLabel.SetBinding(Label.TextColorProperty, "SayingNumber", BindingMode.OneWay, new ColorConverter()); }
// Properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Events & Handlers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void SetupBindings() { FromCountrySpinner.BindingContext = BindingContext; FromCountrySpinner.ItemSource = new List <string> { "US" }; FromCountrySpinner.SetBinding(FieldSpinner.SelectedItemProperty, nameof(MainPageVM.FromCountry)); FromCountrySpinner.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsFromCountryErrored)); FromCountrySpinner.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.FromCountryHelperText)); FromStateSpinner.BindingContext = BindingContext; FromStateSpinner.SetBinding(FieldSpinner.ItemSourceProperty, nameof(MainPageVM.StatesList)); FromStateSpinner.SetBinding(FieldSpinner.SelectedItemProperty, nameof(MainPageVM.FromState)); FromStateSpinner.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsFromStateErrored)); FromStateSpinner.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.FromStateHelperText)); FromZipEntry.BindingContext = BindingContext; FromZipEntry.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.FromZip)); FromZipEntry.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsFromZipErrored)); FromZipEntry.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.FromZipHelperText)); FromCity.BindingContext = BindingContext; FromCity.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.FromCity)); FromCity.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsFromCityErrored)); FromCity.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.FromCityHelperText)); ToCountrySpinner.BindingContext = BindingContext; ToCountrySpinner.ItemSource = new List <string> { "US" }; ToCountrySpinner.SetBinding(FieldSpinner.SelectedItemProperty, nameof(MainPageVM.ToCountry)); ToCountrySpinner.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsToCountryErrored)); ToCountrySpinner.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.ToCountryHelperText)); ToStateSpinner.BindingContext = BindingContext; ToStateSpinner.SetBinding(FieldSpinner.ItemSourceProperty, nameof(MainPageVM.StatesList)); ToStateSpinner.SetBinding(FieldSpinner.SelectedItemProperty, nameof(MainPageVM.ToState)); ToStateSpinner.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsToStateErrored)); ToStateSpinner.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.ToStateHelperText)); ToZipEntry.BindingContext = BindingContext; ToZipEntry.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.ToZip)); ToZipEntry.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsToZipErrored)); ToZipEntry.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.ToZipHelperText)); ToCity.BindingContext = BindingContext; ToCity.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.ToCity)); ToCity.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsToCityErrored)); ToCity.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.ToCityHelperText)); ShippingEntry.BindingContext = BindingContext; ShippingEntry.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.Shipping)); ShippingEntry.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsShippingErrored)); ShippingEntry.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.ShippingHelperText)); AmountEntry.BindingContext = BindingContext; AmountEntry.SetBinding(FieldEntry.TextProperty, nameof(MainPageVM.Amount)); AmountEntry.SetBinding(FieldBase.IsErroredProperty, nameof(MainPageVM.IsAmountErrored)); AmountEntry.SetBinding(FieldBase.HelperTextProperty, nameof(MainPageVM.AmountHelperText)); ResetButton.SetBinding(Button.CommandProperty, nameof(MainPageVM.ResetCommand)); TaxButton.SetBinding(Button.CommandProperty, nameof(MainPageVM.SubmitCommand)); MessageLabel.BindingContext = BindingContext; MessageLabel.SetBinding(Label.TextProperty, nameof(MainPageVM.UserMessage)); MessageLabel.SetBinding(Label.TextColorProperty, nameof(MainPageVM.IsUserMessageErrored), converter: new BoolToTConverter <Color> (ResourceHelper.ErroredTextColor, ResourceHelper.DefaultTextColor)); }