/// <summary> /// Binds a property to a view, this is the standard property binding extension method. /// </summary> /// <typeparam name="TBindingType"></typeparam> /// <param name="bindable"></param> /// <param name="sourceProperty"></param> /// <param name="targetSetter"></param> /// <param name="onlyWhenChanged"></param> /// <returns></returns> public static IDisposable BindProperty <TBindingType>(this IBindable bindable, P <TBindingType> sourceProperty, Action <TBindingType> targetSetter, bool onlyWhenChanged = true) { targetSetter(sourceProperty.Value); if (onlyWhenChanged) { return(bindable.AddBinding(sourceProperty.Where(p => sourceProperty.LastValue != sourceProperty.ObjectValue).Subscribe(targetSetter))); } return(bindable.AddBinding(sourceProperty.Subscribe(targetSetter))); }
/// <summary> /// Binds a property to a view, this is the standard property binding extension method. /// </summary> /// <typeparam name="TBindingType"></typeparam> /// <param name="property"></param> /// <param name="bindable"></param> /// <param name="changed"></param> /// <param name="onlyWhenChanged"></param> /// <returns></returns> public static IDisposable BindTwoWay <TBindingType>(this IBindable bindable, P <TBindingType> property, Action <TBindingType> changed, bool onlyWhenChanged = true) { changed(property.Value); if (onlyWhenChanged) { return (bindable.AddBinding( property.Where(p => !P <TBindingType> .EqualityComparer.Equals(property.Value, property.LastValue)).ObserveOnMainThread().Subscribe(changed)));//uFrame_kbe:ObserveOnMainThread() } return(bindable.AddBinding(property.ObserveOnMainThread().Subscribe(changed)));//uFrame_kbe:ObserveOnMainThread() }
/// <summary> /// Binds a property to a view, this is the standard property binding extension method. /// </summary> /// <typeparam name="TBindingType"></typeparam> /// <param name="property"></param> /// <param name="bindable"></param> /// <param name="changed"></param> /// <param name="onlyWhenChanged"></param> /// <returns></returns> public static IDisposable BindTwoWay <TBindingType>(this IBindable bindable, P <TBindingType> property, Action <TBindingType> changed, bool onlyWhenChanged = true) { changed(property.Value); if (onlyWhenChanged) { return (bindable.AddBinding( property.Where(p => property.LastValue != property.ObjectValue).Subscribe(changed))); } return(bindable.AddBinding(property.Subscribe(changed))); }
/// <summary> /// Binds a property to a view, this is the standard property binding extension method. /// </summary> /// <typeparam name="TBindingType"></typeparam> /// <param name="property"></param> /// <param name="bindable"></param> /// <param name="changed"></param> /// <param name="onlyWhenChanged"></param> /// <returns></returns> public static IDisposable BindProperty <TBindingType>(this IBindable bindable, P <TBindingType> property, Action <TBindingType> changed, bool onlyWhenChanged = true) { changed(property.Value); if (onlyWhenChanged) { return (bindable.AddBinding( property.Where(p => !P <TBindingType> .EqualityComparer.Equals(property.Value, property.LastValue)).Subscribe(changed))); } return(bindable.AddBinding(property.Subscribe(changed))); }
/// <summary> /// Bind to a ViewModel collection. /// </summary> /// <typeparam name="TCollectionItemType">The type that the collection contains.</typeparam> /// <param name="t">This</param> /// <param name="collection">The Model Collection to bind to</param> /// <param name="added"></param> /// <param name="removed"></param> /// <returns>The binding class that allows chaining extra options.</returns> public static IDisposable BindCollection <TCollectionItemType>(this IBindable t, ObservableCollection <TCollectionItemType> collection, Action <TCollectionItemType> added, Action <TCollectionItemType> removed) { NotifyCollectionChangedEventHandler collectionChanged = delegate(NotifyCollectionChangedEventArgs args) { if (added != null && args.NewItems != null) { foreach (var item in args.NewItems) { added((TCollectionItemType)item); } } if (removed != null && args.OldItems != null) { foreach (var item in args.OldItems) { removed((TCollectionItemType)item); } } }; collection.CollectionChanged += collectionChanged; collectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, collection.ToArray())); return(t.AddBinding(Disposable.Create(() => collection.CollectionChanged -= collectionChanged))); }
/// <summary> /// Bind to a ViewModel collection. /// </summary> /// <typeparam name="TCollectionItemType">The type that the collection contains.</typeparam> /// <param name="t">This</param> /// <param name="collection"></param> /// <param name="onAdd"></param> /// <param name="onRemove"></param> /// <returns>The binding class that allows chaining extra options.</returns> public static ModelCollectionBinding <TCollectionItemType> BindCollection <TCollectionItemType>( this IBindable t, ModelCollection <TCollectionItemType> collection, Action <TCollectionItemType> onAdd, Action <TCollectionItemType> onRemove ) { var binding = new ModelCollectionBinding <TCollectionItemType>() { Collection = collection, OnAdd = onAdd, OnRemove = onRemove, }; t.AddBinding(binding); binding.Bind(); return(binding); }
public static IDisposable BindProperty <TBindingType>(this IBindable bindable, Func <Computed <TBindingType> > sourceProperty, Action <TBindingType> targetSetter) { return(bindable.AddBinding(sourceProperty().Subscribe(targetSetter))); }
/// <summary> /// Binds to a commands execution and is diposed with the bindable /// </summary> /// <param name="bindable"></param> /// <param name="sourceCommand"></param> /// <param name="onExecuted"></param> /// <returns></returns> public static IDisposable BindCommandExecuted(this IBindable bindable, ICommand sourceCommand, Action onExecuted) { return(bindable.AddBinding(sourceCommand.Subscribe(delegate { onExecuted(); }))); }
public static IDisposable DisposeWith(this IDisposable disposable, IBindable bindable) { return(bindable.AddBinding(disposable)); }