Exemple #1
0
        /// <summary>Bind to the default property with inline conversion</summary>
        public static TBindable Bind <TBindable, TSource, TDest>(
            this TBindable bindable,
            string path      = bindingContextPath,
            BindingMode mode = BindingMode.Default,
            Func <TSource, TDest> convert     = null,
            Func <TDest, TSource> convertBack = null,
            string stringFormat   = null,
            object source         = null,
            TDest targetNullValue = default,
            TDest fallbackValue   = default) where TBindable : BindableObject
        {
            var converter = new FuncConverter <TSource, TDest, object>(convert, convertBack);

            bindable.Bind(
                DefaultBindableProperties.GetFor(bindable),
                path, mode, converter, null, stringFormat, source, targetNullValue, fallbackValue);
            return(bindable);
        }
        /// <summary>Bind to a specified property with inline conversion</summary>
        public static TBindable Bind <TBindable, TSource, TDest>(
            this TBindable bindable,
            BindableProperty targetProperty,
            string path      = bindingContextPath,
            BindingMode mode = BindingMode.Default,
            Func <TSource?, TDest>?convert     = null,
            Func <TDest?, TSource>?convertBack = null,
            string?stringFormat   = null,
            object?source         = null,
            TDest?targetNullValue = default,
            TDest?fallbackValue   = default) where TBindable : BindableObject
        {
            var converter = new FuncConverter <TSource, TDest, object>(convert, convertBack);

            bindable.SetBinding(
                targetProperty,
                new Binding(path, mode, converter, null, stringFormat, source)
            {
                TargetNullValue = targetNullValue,
                FallbackValue   = fallbackValue
            });
            return(bindable);
        }