/// <summary> /// BindTo takes an Observable stream and applies it to a target /// property. Conceptually it is similar to <c>Subscribe(x => /// target.property = x)</c>, but allows you to use child properties /// without the null checks. /// </summary> /// <typeparam name="TValue">The value type.</typeparam> /// <typeparam name="TTarget">The target type.</typeparam> /// <typeparam name="TTValue">The target value type.</typeparam> /// <param name="observedChange">The target observable to bind to.</param> /// <param name="target">The target object whose property will be set.</param> /// <param name="propertyExpression"> /// An expression representing the target property to set. /// This can be a child property (i.e. <c>x.Foo.Bar.Baz</c>). /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <returns>An object that when disposed, disconnects the binding.</returns> IDisposable BindTo <TValue, TTarget, TTValue>( IObservable <TValue> observedChange, TTarget target, Expression <Func <TTarget, TTValue> > propertyExpression, object conversionHint, IBindingTypeConverter vmToViewConverterOverride = null) where TTarget : class;
this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null, IBindingTypeConverter viewToVmConverterOverride = null)
this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, IObservable <TDontCare> signalViewUpdate, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null, IBindingTypeConverter viewToVmConverterOverride = null)
//protected Settings setting; public ContentPageBase() : base() { bindingDoubleToIntConverter = (IBindingTypeConverter)App.Container.Resolve <IDoubleToIntConverter>(); bindingIntToDoubleConverter = (IBindingTypeConverter)App.Container.Resolve <IIntToDoubleConverter>(); reverseBoolConverter = (IBindingTypeConverter)App.Container.Resolve <IReverseBoolConverter>(); //var _settingsFactory = App.Container.Resolve<ISettingsFactory>(); //setting = _settingsFactory.GetSettings(); }
/// <summary> /// Creates a one-way binding, i.e. a binding that flows from the /// <paramref name="viewModel"/> to the <paramref name="view"/> only. This binding will /// attempt to convert the value of the view model property to the view property if they /// are not of the same type. /// </summary> /// <typeparam name="TViewModel">The type of the view model that is bound.</typeparam> /// <typeparam name="TView">The type of the view that is bound.</typeparam> /// <typeparam name="TVMProp">The type of the property bound on the view model.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <param name="viewModel">The instance of the view model to bind to.</param> /// <param name="view">The instance of the view to bind to.</param> /// <param name="vmProperty"> /// An expression representing the property to be bound to on the view model. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always get the last value of the property chain. /// </param> /// <param name="viewProperty"> /// An expression representing the property to be bound to on the view. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always set the correct property. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> /// <exception cref="ArgumentException"> /// There is no registered converter from <typeparamref name="TVMProp"/> to <typeparamref name="TVProp"/>. /// </exception> IReactiveBinding <TView, TViewModel, TVProp> OneWayBind <TViewModel, TView, TVMProp, TVProp>( TViewModel viewModel, TView view, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, object conversionHint, IBindingTypeConverter vmToViewConverterOverride = null) where TViewModel : class where TView : class, IViewFor;
/// <summary> /// BindTo takes an Observable stream and applies it to a target /// property. Conceptually it is similar to <c>Subscribe(x => /// target.property = x)</c>, but allows you to use child properties /// without the null checks. /// </summary> /// <typeparam name="TValue">The source type.</typeparam> /// <typeparam name="TTarget">The target object type.</typeparam> /// <typeparam name="TTValue">The type of the property on the target object.</typeparam> /// <param name="this">The observable stream to bind to a target property.</param> /// <param name="target">The target object whose property will be set.</param> /// <param name="property"> /// An expression representing the target property to set. /// This can be a child property (i.e. <c>x.Foo.Bar.Baz</c>). /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <returns>An object that when disposed, disconnects the binding.</returns> public static IDisposable BindTo <TValue, TTarget, TTValue>( this IObservable <TValue> @this, TTarget target, Expression <Func <TTarget, TTValue> > property, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null) where TTarget : class { return(binderImplementation.BindTo(@this, target, property, conversionHint, vmToViewConverterOverride)); }
/// <summary> /// Binds the specified view model property to the given view property, and /// provide a custom view update signaller to signal when the view property has been updated. /// </summary> /// <typeparam name="TViewModel">The type of the view model being bound.</typeparam> /// <typeparam name="TView">The type of the view being bound.</typeparam> /// <typeparam name="TVMProp">The type of the property bound on the view model.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <param name="view">The instance of the view to bind.</param> /// <typeparam name="TDontCare"> /// A dummy type, only the fact that <paramref name="signalViewUpdate"/> /// emits values is considered, not the actual values emitted. /// </typeparam> /// <param name="viewModel">The instance of the view model to bind.</param> /// <param name="vmProperty"> /// An expression indicating the property that is bound on the view model. /// This can be a chain of properties of the form. <code>vm => vm.Foo.Bar.Baz</code> /// and the binder will attempt to subscribe to changes on each recursively. /// </param> /// <param name="viewProperty"> /// The property on the view that is to be bound. /// This can be a chain of properties of the form. <code>view => view.Foo.Bar.Baz</code> /// and the binder will attempt to set the last one each time the view model property is updated. /// </param> /// <param name="signalViewUpdate"> /// An observable, that when signaled, indicates that the view property /// has been changed, and that the binding should update the view model /// property accordingly. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <param name="viewToVMConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// view to viewModel property. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> public static IReactiveBinding <TView, TViewModel, Tuple <object, bool> > Bind <TViewModel, TView, TVMProp, TVProp, TDontCare>( this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, IObservable <TDontCare> signalViewUpdate, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null, IBindingTypeConverter viewToVMConverterOverride = null) where TViewModel : class where TView : class, IViewFor => binderImplementation.Bind(viewModel, view, vmProperty, viewProperty, signalViewUpdate, conversionHint, vmToViewConverterOverride, viewToVMConverterOverride);
BindToProperty <TViewModel, TView, TVMValue, TVMCanExecute, TVProp, TVEnabledProp>( this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMValue> > vmCommandValue, Expression <Func <TViewModel, TVMCanExecute> > vmCommandCanExecute, Expression <Func <TView, TVProp> > vProperty, Expression <Func <TView, TVEnabledProp> > vEnabled, IBindingTypeConverter vmToViewConverterOverride, CompositeDisposable disposables) where TViewModel : class where TView : class, IViewFor { view.Bind(viewModel, vmCommandValue, vProperty, vmToViewConverterOverride: vmToViewConverterOverride) .DisposeWith(disposables); view.Bind(viewModel, vmCommandCanExecute, vEnabled).DisposeWith(disposables); }
/// <summary> /// Binds the given property on the view model to a given property on the view in a one-way (view model to view) fashion. /// </summary> /// <typeparam name="TViewModel">The type of the view model.</typeparam> /// <typeparam name="TView">The type of the view.</typeparam> /// <typeparam name="TVMProp">The type of view model property.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <param name="view"> /// The instance of the view object which is bound. Usually, it is the. <code>this</code> /// instance. /// </param> /// <param name="viewModel"> /// The view model that is bound. /// It is usually set to the <see cref="IViewFor.ViewModel"/> property of the <paramref name="view"/>.</param> /// <param name="vmProperty"> /// An expression indicating the property that is bound on the view model. /// This can be a chain of properties of the form. <code>vm => vm.Foo.Bar.Baz</code> /// and the binder will attempt to subscribe to changes on each recursively. /// </param> /// <param name="viewProperty"> /// The property on the view that is to be bound. /// This can be a chain of properties of the form. <code>view => view.Foo.Bar.Baz</code> /// and the binder will attempt to set the last one each time the view model property is updated. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> public static IReactiveBinding <TView, TViewModel, TVProp> OneWayBind <TViewModel, TView, TVMProp, TVProp>( this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null) where TViewModel : class where TView : class, IViewFor { return(binderImplementation.OneWayBind( viewModel, view, vmProperty, viewProperty, conversionHint, vmToViewConverterOverride)); }
/// <summary> /// Creates a one-way binding, i.e. a binding that flows from the /// <paramref name="viewModel"/> to the <paramref name="view"/> only. This binding will /// attempt to convert the value of the view model property to the view property if they /// are not of the same type. /// </summary> /// <typeparam name="TViewModel">The type of the view model that is bound.</typeparam> /// <typeparam name="TView">The type of the view that is bound.</typeparam> /// <typeparam name="TVMProp">The type of the property bound on the view model.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <param name="viewModel">The instance of the view model to bind to.</param> /// <param name="view">The instance of the view to bind to.</param> /// <param name="vmProperty"> /// An expression representing the property to be bound to on the view model. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always get the last value of the property chain. /// </param> /// <param name="viewProperty"> /// An expression representing the property to be bound to on the view. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always set the correct property. /// /// If it is left null, the framework will attempt to automagically figure out /// the control and property that is to be bound, by looking for a control of the /// same name as the <paramref name="vmProperty"/>, and its most natural property. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// Delegate to convert the value of the view model's property's type to a value of the /// view's property's type. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> /// <exception cref="ArgumentException"> /// There is no registered converter from <typeparamref name="TVMProp"/> to <typeparamref name="TVProp"/>. /// </exception> public IReactiveBinding <TView, TViewModel, TVProp> OneWayBind <TViewModel, TView, TVMProp, TVProp>( TViewModel viewModel, TView view, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null) where TViewModel : class where TView : class, IViewFor { var vmExpression = Reflection.Rewrite(vmProperty.Body); var viewExpression = Reflection.Rewrite(viewProperty.Body); var viewType = viewExpression.Type; var converter = vmToViewConverterOverride ?? GetConverterForTypes(typeof(TVMProp), viewType); if (converter == null) { throw new ArgumentException($"Can't convert {typeof(TVMProp)} to {viewType}. To fix this, register a IBindingTypeConverter"); } var ret = EvalBindingHooks(viewModel, view, vmExpression, viewExpression, BindingDirection.OneWay); if (!ret) { return(null); } var source = Reflection.ViewModelWhenAnyValue(viewModel, view, vmExpression) .SelectMany(x => { object tmp; if (!converter.TryConvert(x, viewType, conversionHint, out tmp)) { return(Observable <TVProp> .Empty); } return(Observable.Return(tmp == null ? default(TVProp) : (TVProp)tmp)); }); IDisposable disp = BindToDirect(source, view, viewExpression); return(new ReactiveBinding <TView, TViewModel, TVProp>(view, viewModel, viewExpression, vmExpression, source, BindingDirection.OneWay, disp)); }
/// <summary> /// BindTo takes an Observable stream and applies it to a target /// property. Conceptually it is similar to <c>Subscribe(x => /// target.property = x)</c>, but allows you to use child properties /// without the null checks. /// </summary> /// <typeparam name="TValue">The source type.</typeparam> /// <typeparam name="TTarget">The target object type.</typeparam> /// <typeparam name="TTValue">The type of the property on the target object.</typeparam> /// <param name="observedChange">The observable to apply to the target property.</param> /// <param name="target">The target object whose property will be set.</param> /// <param name="propertyExpression"> /// An expression representing the target property to set. /// This can be a child property (i.e. <c>x.Foo.Bar.Baz</c>).</param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// Delegate to convert the value of the view model's property's type to a value of the /// view's property's type. /// </param> /// <returns>An object that when disposed, disconnects the binding.</returns> public IDisposable BindTo <TValue, TTarget, TTValue>( IObservable <TValue> observedChange, TTarget target, Expression <Func <TTarget, TTValue> > propertyExpression, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null) where TTarget : class { if (target == null) { throw new ArgumentNullException(nameof(target)); } var viewExpression = Reflection.Rewrite(propertyExpression.Body); var ret = EvalBindingHooks(observedChange, target, null, viewExpression, BindingDirection.OneWay); if (!ret) { return(Disposable.Empty); } var converter = vmToViewConverterOverride ?? GetConverterForTypes(typeof(TValue), typeof(TTValue)); if (converter == null) { throw new ArgumentException($"Can't convert {typeof(TValue)} to {typeof(TTValue)}. To fix this, register a IBindingTypeConverter"); } var source = observedChange.SelectMany(x => { object tmp; if (!converter.TryConvert(x, typeof(TTValue), conversionHint, out tmp)) { return(Observable <TTValue> .Empty); } return(Observable.Return(tmp == null ? default(TTValue) : (TTValue)tmp)); }); return(BindToDirect(source, target, viewExpression)); }
/// <summary> /// Binds the specified view model property to the given view property. /// </summary> /// <typeparam name="TViewModel">The type of the view model being bound.</typeparam> /// <typeparam name="TView">The type of the view being bound.</typeparam> /// <typeparam name="TVMProp">The type of the property bound on the view model.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <param name="view">The instance of the view to bind.</param> /// <param name="viewModel">The instance of the view model to bind.</param> /// <param name="vmProperty"> /// An expression indicating the property that is bound on the view model. /// This can be a chain of properties of the form. <code>vm => vm.Foo.Bar.Baz</code> /// and the binder will attempt to subscribe to changes on each recursively. /// </param> /// <param name="viewProperty"> /// The property on the view that is to be bound. /// This can be a chain of properties of the form. <code>view => view.Foo.Bar.Baz</code> /// and the binder will attempt to set the last one each time the view model property is updated. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <param name="viewToVMConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// view to viewModel property. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> public static IReactiveBinding <TView, TViewModel, Tuple <object, bool> > Bind <TViewModel, TView, TVMProp, TVProp>( this TView view, TViewModel viewModel, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, object conversionHint = null, IBindingTypeConverter vmToViewConverterOverride = null, IBindingTypeConverter viewToVMConverterOverride = null) where TViewModel : class where TView : class, IViewFor { return(binderImplementation.Bind( viewModel, view, vmProperty, viewProperty, (IObservable <Unit>)null, conversionHint, vmToViewConverterOverride, viewToVMConverterOverride)); }
/// <summary> /// Creates a two-way binding between a view model and a view. /// This binding will attempt to convert the values of the /// view and view model properties using a <see cref="IBindingTypeConverter"/> /// if they are not of the same type. /// </summary> /// <typeparam name="TViewModel">The type of the view model that is bound.</typeparam> /// <typeparam name="TView">The type of the view being bound.</typeparam> /// <typeparam name="TVMProp">The type of the property bound on the view model.</typeparam> /// <typeparam name="TVProp">The type of the property bound on the view.</typeparam> /// <typeparam name="TDontCare"> /// A dummy type, only the fact that <paramref name="signalViewUpdate"/> /// emits values is considered, not the actual values emitted. /// </typeparam> /// <param name="viewModel">The instance of the view model object to be bound.</param> /// <param name="view">The instance of the view object to be bound.</param> /// <param name="vmProperty"> /// An expression representing the property to be bound to on the view model. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always get and set the correct property. /// </param> /// <param name="viewProperty"> /// An expression representing the property to be bound to on the view. /// This can be a child property, for example <c>x => x.Foo.Bar.Baz</c> in which case /// the binding will attempt to subscribe recursively to updates in order to /// always get and set the correct property. /// /// If it is left null, the framework will attempt to automagically figure out /// the control and property that is to be bound, by looking for a control of the /// same name as the <paramref name="vmProperty"/>, and its most natural property. /// </param> /// <param name="signalViewUpdate"> /// An observable, that when signaled, indicates that the view property /// has been changed, and that the binding should update the view model /// property accordingly. /// </param> /// <param name="conversionHint"> /// An object that can provide a hint for the converter. /// The semantics of this object is defined by the converter used. /// </param> /// <param name="vmToViewConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// viewModel to view property. /// </param> /// <param name="viewToVMConverterOverride"> /// An optional <see cref="IBindingTypeConverter"/> to use when converting from the /// view to viewModel property. /// </param> /// <returns> /// An instance of <see cref="IDisposable"/> that, when disposed, /// disconnects the binding. /// </returns> public IReactiveBinding <TView, TViewModel, Tuple <object, bool> > Bind <TViewModel, TView, TVMProp, TVProp, TDontCare>( TViewModel viewModel, TView view, Expression <Func <TViewModel, TVMProp> > vmProperty, Expression <Func <TView, TVProp> > viewProperty, IObservable <TDontCare> signalViewUpdate, object conversionHint, IBindingTypeConverter vmToViewConverterOverride = null, IBindingTypeConverter viewToVMConverterOverride = null) where TViewModel : class where TView : class, IViewFor { var vmToViewConverter = vmToViewConverterOverride ?? GetConverterForTypes(typeof(TVMProp), typeof(TVProp)); var viewToVMConverter = viewToVMConverterOverride ?? GetConverterForTypes(typeof(TVProp), typeof(TVMProp)); if (vmToViewConverter == null || viewToVMConverter == null) { throw new ArgumentException( $"Can't two-way convert between {typeof(TVMProp)} and {typeof(TVProp)}. To fix this, register a IBindingTypeConverter or call the version with converter Funcs."); } OutFunc <TVMProp, TVProp> vmToViewFunc = (TVMProp vmValue, out TVProp vValue) => { object tmp; var result = vmToViewConverter.TryConvert(vmValue, typeof(TVProp), conversionHint, out tmp); vValue = result ? (TVProp)tmp : default(TVProp); return(result); }; OutFunc <TVProp, TVMProp> viewToVmFunc = (TVProp vValue, out TVMProp vmValue) => { object tmp; var result = viewToVMConverter.TryConvert(vValue, typeof(TVMProp), conversionHint, out tmp); vmValue = result ? (TVMProp)tmp : default(TVMProp); return(result); }; return(BindImpl(viewModel, view, vmProperty, viewProperty, signalViewUpdate, vmToViewFunc, viewToVmFunc)); }
public SettingsPage() { InitializeComponent(); bindingPaddingTopBottomConverter = (IBindingTypeConverter)App.Container.Resolve <IPaddingTopBottomConverter>(); settings = App.Container.Resolve <ISettingsFactory>().GetSettings(); ViewModel = (SettingsViewModel)App.Container.Resolve <ISettingsViewModel>(); var fontSize = settings.FontSize; this.Padding = new Thickness(10, getDevicePadding(), 10, 5); isManualFontLabel = new Label() { Text = "Enable Manual Font", VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start }; isManualFont = new Switch() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.EndAndExpand }; isManualFontGrid = new TwoValueHorizontalGrid().Create(0d, 80d); isManualFontGrid.Children.Add(isManualFontLabel, 0, 0); isManualFontGrid.Children.Add(isManualFont, 1, 0); fontSliderLabel = new Label { Text = $"Custom Font Size is {fontSize}", HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; fontSlider = new Slider { Maximum = Constants.FontSizeMax, Minimum = 12, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; fontSliderGrid = new TwoValueHorizontalGrid().Create(); fontSliderGrid.Children.Add(fontSliderLabel, 0, 0); fontSliderGrid.Children.Add(fontSlider, 1, 0); showConnectionErrorsLabel = new Label() { Text = "Show Connection Errors", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Start }; showConnectionErrors = new Switch() { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.End }; showConnectionErrorsGrid = new TwoValueHorizontalGrid().Create(); showConnectionErrorsGrid.Children.Add(showConnectionErrorsLabel, 0, 0); showConnectionErrorsGrid.Children.Add(showConnectionErrors, 1, 0); viewCellManualFont = new ViewCell() { View = isManualFontGrid }; viewCellSlider = new ViewCell() { View = fontSliderGrid }; viewCellShowErrors = new ViewCell() { View = showConnectionErrorsGrid }; var stacklayout = new StackLayout() { Orientation = StackOrientation.Vertical, Padding = new Thickness(10, 10, 10, 10), VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; var seperator1 = new StackLayout { HeightRequest = 1, BackgroundColor = Color.Gray, HorizontalOptions = LayoutOptions.FillAndExpand }; sectionLabelInterface = new Label() { Text = "Interface", TextColor = Color.Gray }; var seperator2 = new StackLayout { HeightRequest = 1, BackgroundColor = Color.Gray, HorizontalOptions = LayoutOptions.FillAndExpand }; sectionLabelDiagnostics = new Label() { Text = "Diagnostics", TextColor = Color.Gray }; stacklayout.Children.Add(sectionLabelInterface); stacklayout.Children.Add(seperator1); stacklayout.Children.Add(isManualFontGrid); stacklayout.Children.Add(fontSliderGrid); stacklayout.Children.Add(sectionLabelDiagnostics); stacklayout.Children.Add(seperator2); stacklayout.Children.Add(showConnectionErrorsGrid); this.Content = stacklayout; this .WhenActivated( disposables => { this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.fontSliderGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.showConnectionErrorsGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.sectionLabelInterface.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.sectionLabelDiagnostics.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this.Bind(ViewModel, vm => vm.FontSize, x => x.fontSlider.Value, vmToViewConverterOverride: bindingIntToDoubleConverter, viewToVMConverterOverride: bindingDoubleToIntConverter) .DisposeWith(disposables); this.fontSlider.Events().ValueChanged .Throttle(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler) .Do((x) => { var rounded = Math.Round(x.NewValue); fontSliderLabel.Text = $"Custom Font Size is {rounded}"; MessagingCenter.Send <ISettingsPage>(this, "mSettingsFontChanged"); }) .Select(x => Unit.Default) .InvokeCommand(ViewModel.FontSliderChanged) .DisposeWith(disposables); this.isManualFont.Events().Toggled .Select(x => Unit.Default) .InvokeCommand(ViewModel.IsManualFontOnClicked) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .Bind(this.ViewModel, x => x.IsManualFontOn, x => x.isManualFont.IsToggled) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.fontSliderLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.IsManualFontOn, x => x.fontSlider.IsEnabled) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.showConnectionErrorsLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .Bind(this.ViewModel, x => x.ShowConnectionErrors, x => x.showConnectionErrors.IsToggled) .DisposeWith(disposables); this.BindCommand( this.ViewModel, x => x.ShowConnectionErrorsCommand, x => x.showConnectionErrors, nameof(showConnectionErrors.Toggled)) .DisposeWith(disposables); }); }
private IDisposable BindComboBox <T>( Expression <Func <SeasonFormViewModel, T> > vmProperty, Expression <Func <SeasonFormControl, object> > viewProperty, IBindingTypeConverter converter) => this.Bind(this.ViewModel, vmProperty, viewProperty, null, converter, converter);
public ContentViewBase() : base() { bindingDoubleToIntConverter = (IBindingTypeConverter)App.Container.Resolve <IDoubleToIntConverter>(); bindingIntToDoubleConverter = (IBindingTypeConverter)App.Container.Resolve <IIntToDoubleConverter>(); }
public SettingsPage() { InitializeComponent(); bindingPaddingTopBottomConverter = (IBindingTypeConverter)App.Container.Resolve <IPaddingTopBottomConverter>(); ViewModel = (SettingsViewModel)App.Container.Resolve <ISettingsViewModel>(); var fontSize = ViewModel.FontSize; this.Padding = new Thickness(10, getDevicePadding(), 10, 5); isManualFontLabel = new Label() { Text = "Enable Manual Font", VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start }; isManualFont = new Switch() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.EndAndExpand }; isManualFontGrid = new TwoValueHorizontalGrid().Create(0d, 80d); isManualFontGrid.Children.Add(isManualFontLabel, 0, 0); isManualFontGrid.Children.Add(isManualFont, 1, 0); fontSliderLabel = new Label { //Text = $"Custom Font Size is {fontSize}", HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; fontSlider = new Slider { Maximum = ViewModel.defaultsFactory.GetFontSizeMax(), Minimum = 12, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; fontSliderGrid = new TwoValueHorizontalGrid().Create(); fontSliderGrid.Children.Add(fontSliderLabel, 0, 0); fontSliderGrid.Children.Add(fontSlider, 1, 0); showConnectionErrorsLabel = new Label() { Text = "Show Connection Errors", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Start }; showConnectionErrors = new Switch() { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.End }; showConnectionErrorsGrid = new TwoValueHorizontalGrid().Create(); showConnectionErrorsGrid.Children.Add(showConnectionErrorsLabel, 0, 0); showConnectionErrorsGrid.Children.Add(showConnectionErrors, 1, 0); viewCellManualFont = new ViewCell() { View = isManualFontGrid }; viewCellSlider = new ViewCell() { View = fontSliderGrid }; viewCellShowErrors = new ViewCell() { View = showConnectionErrorsGrid }; var stacklayout = new StackLayout() { Orientation = StackOrientation.Vertical, Padding = new Thickness(10, 10, 10, 10), VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; var seperator1 = new StackLayout { HeightRequest = 1, BackgroundColor = Color.Gray, HorizontalOptions = LayoutOptions.FillAndExpand }; sectionLabelInterface = new Label() { Text = "Interface", TextColor = Color.Gray }; var seperator2 = new StackLayout { HeightRequest = 1, BackgroundColor = Color.Gray, HorizontalOptions = LayoutOptions.FillAndExpand }; sectionLabelDiagnostics = new Label() { Text = "Diagnostics", TextColor = Color.Gray }; stacklayout.Children.Add(sectionLabelInterface); stacklayout.Children.Add(seperator1); stacklayout.Children.Add(isManualFontGrid); stacklayout.Children.Add(fontSliderGrid); stacklayout.Children.Add(sectionLabelDiagnostics); stacklayout.Children.Add(seperator2); stacklayout.Children.Add(showConnectionErrorsGrid); this.Content = stacklayout; this .WhenActivated( disposables => { this .OneWayBind(ViewModel, vm => vm.Title, x => x.Title) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.fontSliderGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.showConnectionErrorsGrid.Margin, vmToViewConverterOverride: bindingPaddingTopBottomConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.sectionLabelInterface.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.sectionLabelDiagnostics.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this.Bind(ViewModel, vm => vm.FontSize, x => x.fontSlider.Value, vmToViewConverterOverride: bindingIntToDoubleConverter, viewToVMConverterOverride: bindingDoubleToIntConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.isManualFontLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .Bind(this.ViewModel, x => x.IsManualFontOn, x => x.isManualFont.IsToggled) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSliderLabel, x => x.fontSliderLabel.Text) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.fontSliderLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.IsManualFontOn, x => x.fontSlider.IsEnabled) .DisposeWith(disposables); this .OneWayBind(this.ViewModel, x => x.FontSize, x => x.showConnectionErrorsLabel.FontSize, vmToViewConverterOverride: bindingIntToDoubleConverter) .DisposeWith(disposables); this .Bind(this.ViewModel, x => x.ShowConnectionErrors, x => x.showConnectionErrors.IsToggled) .DisposeWith(disposables); }); }