Esempio n. 1
0
        public static T Bind <T, TViewModel>(this T element,
                                             MvxInlineBindingTarget <TViewModel> target,
                                             string targetPath,
                                             string sourcePath,
                                             IMvxValueConverter converter = null,
                                             object converterParameter    = null,
                                             object fallbackValue         = null,
                                             MvxBindingMode mode          = MvxBindingMode.Default)
        {
            if (string.IsNullOrEmpty(targetPath))
            {
                targetPath = MvxBindingSingletonCache.Instance.DefaultBindingNameLookup.DefaultFor(typeof(T));
            }

            var bindingDescription = new MvxBindingDescription(
                targetPath,
                sourcePath,
                converter,
                converterParameter,
                fallbackValue,
                mode);

            target.BindingContextOwner.AddBinding(element, bindingDescription);

            return(element);
        }
        /// <summary>
        /// Creates a custom binding for the <see cref="TextView"/>.
        /// Remember to call <see cref="IMvxViewBindingManager.UnbindView"/> on the view after you're done
        /// using it.
        /// </summary>
        public static void BindToText(this TextView view, INotifyPropertyChanged source,
                                      string sourcePropertyName, IMvxValueConverter converter = null,
                                      object converterParameter = null)
        {
            var activity = view.Context as IMvxBindingActivity;
            if (activity == null)
                return;

            var description = new MvxBindingDescription
            {
                SourcePropertyPath = sourcePropertyName,
                Converter = converter,
                ConverterParameter = converterParameter,
                TargetName = "Text",
                Mode = MvxBindingMode.OneWay
            }.ToEnumerable();

            var tag = view.GetBindingTag ();
            if (tag != null) {
                MvxBindingTrace.Trace(
                    MvxTraceLevel.Warning,
                    "Replacing binding tag for a TextView " + view.Id);
            }

            view.SetBindingTag (new MvxViewBindingTag (description));
            activity.BindingManager.BindView (view, source);
        }
 public MvxFluentBindingDescription <TTarget, TSource> WithConversion(IMvxValueConverter converter,
                                                                      object converterParameter = null)
 {
     SourceStepDescription.Converter          = converter;
     SourceStepDescription.ConverterParameter = converterParameter;
     return(this);
 }
 public MvxBindingDescription(string targetName, string sourcePropertyPath, IMvxValueConverter converter, object converterParameter, object fallbackValue, MvxBindingMode mode)
 {
     TargetName = targetName;
     SourcePropertyPath = sourcePropertyPath;
     Converter = converter;
     ConverterParameter = converterParameter;
     FallbackValue = fallbackValue;
     Mode = mode;
 }
 public MvxBindingDescription(string targetName, string sourcePropertyPath, IMvxValueConverter converter, object converterParameter, object fallbackValue, MvxBindingMode mode)
 {
     TargetName         = targetName;
     SourcePropertyPath = sourcePropertyPath;
     Converter          = converter;
     ConverterParameter = converterParameter;
     FallbackValue      = fallbackValue;
     Mode = mode;
 }
Esempio n. 6
0
 public static T Bind <T, TViewModel>(this T element,
                                      MvxInlineBindingTarget <TViewModel> target,
                                      Expression <Func <TViewModel, object> > sourcePropertyPath,
                                      IMvxValueConverter converter,
                                      object converterParameter = null,
                                      object fallbackValue      = null,
                                      MvxBindingMode mode       = MvxBindingMode.Default)
 {
     return(element.Bind(target, null, sourcePropertyPath, converter, converterParameter, fallbackValue, mode));
 }
Esempio n. 7
0
        protected static IValueConverter GetConverter(IMvxValueConverter converter)
        {
            if (converter == null)
            {
                return(null);
            }

            // TODO - consider caching this wrapper - it is a tiny bit wasteful creating a wrapper for each binding
            return(new MvxNativeValueConverter(converter));
        }
Esempio n. 8
0
 public static void Bind <TTarget, TSource>(this TTarget bindingOwner,
                                            Expression <Func <TSource, object> > sourcePropertyPath,
                                            IMvxValueConverter converter = null,
                                            object converterParameter    = null,
                                            object fallbackValue         = null,
                                            MvxBindingMode mode          = MvxBindingMode.Default)
     where TTarget : class, IMvxBindingContextOwner
 {
     bindingOwner.Bind(bindingOwner, string.Empty, sourcePropertyPath, converter, converterParameter,
                       fallbackValue, mode);
 }
 public MvxBindingDescription(string targetName, string sourcePropertyPath, IMvxValueConverter converter,
                              object converterParameter, object fallbackValue, MvxBindingMode mode)
 {
     this.TargetName = targetName;
     this.Mode = mode;
     this.Source = new MvxPathSourceStepDescription
     {
         SourcePropertyPath = sourcePropertyPath,
         Converter = converter,
         ConverterParameter = converterParameter,
         FallbackValue = fallbackValue,
     };
 }
Esempio n. 10
0
 public MvxBindingDescription(string targetName, string sourcePropertyPath, IMvxValueConverter converter,
                              object converterParameter, object fallbackValue, MvxBindingMode mode)
 {
     this.TargetName = targetName;
     this.Mode       = mode;
     this.Source     = new MvxPathSourceStepDescription
     {
         SourcePropertyPath = sourcePropertyPath,
         Converter          = converter,
         ConverterParameter = converterParameter,
         FallbackValue      = fallbackValue,
     };
 }
Esempio n. 11
0
        public static T Bind <T, TViewModel>(this T element,
                                             MvxInlineBindingTarget <TViewModel> target,
                                             Expression <Func <T, object> > targetPropertyPath,
                                             Expression <Func <TViewModel, object> > sourcePropertyPath,
                                             IMvxValueConverter converter,
                                             object converterParameter = null,
                                             object fallbackValue      = null,
                                             MvxBindingMode mode       = MvxBindingMode.Default)
        {
            var parser     = MvxBindingSingletonCache.Instance.PropertyExpressionParser;
            var sourcePath = parser.Parse(sourcePropertyPath).Print();
            var targetPath = targetPropertyPath == null ? null : parser.Parse(targetPropertyPath).Print();

            return(element.Bind(target, targetPath, sourcePath, converter, converterParameter, fallbackValue, mode));
        }
Esempio n. 12
0
        public static void Bind <TTarget, TSource>(this IMvxBindingContextOwner bindingOwner,
                                                   TTarget target,
                                                   Expression <Func <TTarget, object> > targetProperty,
                                                   Expression <Func <TSource, object> > sourcePropertyPath,
                                                   IMvxValueConverter converter = null,
                                                   object converterParameter    = null,
                                                   object fallbackValue         = null,
                                                   MvxBindingMode mode          = MvxBindingMode.Default)
            where TTarget : class
        {
            var parser = PropertyExpressionParser;

            var parsedTargetPath = parser.Parse(targetProperty);
            var parsedSource     = parser.Parse(sourcePropertyPath);

            bindingOwner.Bind(target, converter, converterParameter, fallbackValue, mode, parsedTargetPath, parsedSource);
        }
Esempio n. 13
0
        public static void Bind <TTarget, TSource>(this IMvxBindingContextOwner bindingOwner,
                                                   TTarget target,
                                                   string eventOrPropertyName,
                                                   Expression <Func <TSource, object> > sourcePropertyPath,
                                                   IMvxValueConverter converter = null,
                                                   object converterParameter    = null,
                                                   object fallbackValue         = null,
                                                   MvxBindingMode mode          = MvxBindingMode.Default)
            where TTarget : class
        {
            var parser       = PropertyExpressionParser;
            var parsedSource = parser.Parse(sourcePropertyPath);

            if (string.IsNullOrEmpty(eventOrPropertyName))
            {
                eventOrPropertyName = DefaultBindingNameLookup.DefaultFor(typeof(TTarget));
            }

            bindingOwner.Bind(target, converter, converterParameter, fallbackValue, mode, eventOrPropertyName,
                              parsedSource.Print());
        }
Esempio n. 14
0
 public GroupDescription(string propertyName, IMvxValueConverter converter)
 {
     this.PropertyName = propertyName;
     this.Converter    = converter;
 }
 public void AddOrOverwrite(string name, IMvxValueConverter converter)
 {
     _converters[name] = converter;
 }
Esempio n. 16
0
 public MvxNativeValueConverter(IMvxValueConverter wrapped)
 {
     _wrapped = wrapped;
 }
Esempio n. 17
0
        private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter, object fallbackValue,
                                               Type targetType, out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
        {
            ClearAll();
            MvxBindingSingletonCache.Initialize();

            var mockSourceBindingFactory = new Mock <IMvxSourceBindingFactory>();

            Ioc.RegisterSingleton(mockSourceBindingFactory.Object);

            var mockTargetBindingFactory = new Mock <IMvxTargetBindingFactory>();

            Ioc.RegisterSingleton(mockTargetBindingFactory.Object);

            var realSourceStepFactory = new MvxSourceStepFactory();

            realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
            Ioc.RegisterSingleton <IMvxSourceStepFactory>(realSourceStepFactory);

            var sourceText         = "sourceText";
            var targetName         = "targetName";
            var source             = new { Value = 1 };
            var target             = new { Value = 2 };
            var bindingDescription = new MvxBindingDescription
            {
                Source = new MvxPathSourceStepDescription()
                {
                    Converter          = valueConverter,
                    ConverterParameter = converterParameter,
                    FallbackValue      = fallbackValue,
                    SourcePropertyPath = sourceText,
                },
                Mode       = MvxBindingMode.TwoWay,
                TargetName = targetName
            };

            mockSource = new MockSourceBinding();
            mockTarget = new MockTargetBinding()
            {
                TargetType = targetType
            };
            mockTarget.DefaultMode = MvxBindingMode.TwoWay;

            var localSource = mockSource;

            mockSourceBindingFactory
            .Setup(x => x.CreateBinding(It.IsAny <object>(), It.Is <string>(s => s == sourceText)))
            .Returns((object a, string b) => localSource);
            var localTarget = mockTarget;

            mockTargetBindingFactory
            .Setup(x => x.CreateBinding(It.IsAny <object>(), It.Is <string>(s => s == targetName)))
            .Returns((object a, string b) => localTarget);

            mockSource.TryGetValueResult = true;
            mockSource.TryGetValueValue  = "TryGetValueValue";

            var request = new MvxBindingRequest(source, target, bindingDescription);
            var toTest  = new MvxFullBinding(request);

            return(toTest);
        }
 private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter,
                                        Type targetType, out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
 {
     return TestSetupCommon(valueConverter, converterParameter, new { Value = 4 }, targetType, out mockSource, out mockTarget);
 }
Esempio n. 19
0
 public GroupedListAdapter(IMvxValueConverter keyConverter, Context context)
     : base(context)
 {
     _keyConverter = keyConverter;
 }
Esempio n. 20
0
 public SimplePickerElement(string caption, object value, IMvxValueConverter displayValueConverter = null)
     : base(caption, value)
 {
     DisplayValueConverter = displayValueConverter ?? new ToStringDisplayValueConverter();
 }
 public void AddOrOverwrite(string name, IMvxValueConverter converter)
 {
     _converters[name] = converter;
 }
 public GroupedListAdapter(Context context, IMvxAndroidBindingContext bindingContext, IMvxValueConverter keyConverter)
     : base(context, bindingContext)
 {
     _keyConverter = keyConverter;
 }
 public void Register(Type viewModelType, Type viewType, IMvxValueConverter converter)
 {
     _lookup[new Key(viewModelType, viewType)] = converter;
 }
Esempio n. 24
0
 private static void Bind(this IMvxBindingContextOwner bindingOwner, object target, IMvxValueConverter converter,
                          object converterParameter, object fallbackValue, MvxBindingMode mode,
                          IMvxParsedExpression parsedTargetPath, IMvxParsedExpression parsedSourcePath)
 {
     bindingOwner.Bind(target, converter, converterParameter, fallbackValue, mode, parsedTargetPath.Print(),
                       parsedSourcePath.Print());
 }
Esempio n. 25
0
 public SimplePickerElement(string caption, object value, IMvxValueConverter displayValueConverter = null)
     : base(caption, value)
 {
     this.DisplayValueConverter = displayValueConverter ?? new ToStringDisplayValueConverter();
     this.BackgroundColor       = (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) ? UIColor.White : UIColor.Black;
 }
Esempio n. 26
0
 public void Register(Type viewModelType, Type viewType, IMvxValueConverter converter)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
 public MvxValueConverterValueCombiner(IMvxValueConverter valueConverter)
 {
     _valueConverter = valueConverter;
 }
Esempio n. 28
0
 public TableSource(IMvxValueConverter keyConverter, UITableView tableView)
     : base(tableView)
 {
     _keyConverter = keyConverter;
 }
        protected static IValueConverter GetConverter(IMvxValueConverter converter)
        {
            if (converter == null)
                return null;

            // TODO - consider caching this wrapper - it is a tiny bit wasteful creating a wrapper for each binding
            return new MvxNativeValueConverter(converter);
        }
 public void Register(Type viewModelType, Type viewType, IMvxValueConverter converter)
 {
     throw new NotImplementedException();
 }
 public void Register(Type viewModelType, Type viewType, IMvxValueConverter converter)
 {
     _lookup[new Key(viewModelType, viewType)] = converter;
 }
 public MvxNativeValueConverter(IMvxValueConverter wrapped)
 {
     _wrapped = wrapped;
 }
 public MvxValueConverterValueCombiner(IMvxValueConverter valueConverter)
 {
     this._valueConverter = valueConverter;
 }
Esempio n. 34
0
 private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter,
                                        Type targetType, out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
 {
     return(TestSetupCommon(valueConverter, converterParameter, new { Value = 4 }, targetType, out mockSource, out mockTarget));
 }
Esempio n. 35
0
        public static void BindTextViewText <TSourceType>(this Activity activity, int targetViewId, INotifyPropertyChanged source, string sourcePropertyName, IMvxValueConverter converter = null, object converterParameter = null)
        {
            var description = new MvxBindingDescription()
            {
                SourcePropertyPath = sourcePropertyName,
                Converter          = converter,
                ConverterParameter = converterParameter,
                TargetName         = "Text",
                Mode = MvxBindingMode.OneWay
            };

            activity.BindView <TextView>(targetViewId, source, description);
        }
Esempio n. 36
0
        private static void Bind(this IMvxBindingContextOwner bindingOwner, object target, IMvxValueConverter converter,
                                 object converterParameter, object fallbackValue, MvxBindingMode mode,
                                 string parsedTargetPath, string parsedSourcePath)
        {
            var description = new MvxBindingDescription
            {
                TargetName         = parsedTargetPath,
                SourcePropertyPath = parsedSourcePath,
                Converter          = converter,
                ConverterParameter = converterParameter,
                FallbackValue      = fallbackValue,
                Mode = mode
            };

            bindingOwner.AddBinding(target, description);
        }
Esempio n. 37
0
 public static void BindTextViewText(this Activity activity, int targetViewId, INotifyPropertyChanged source, string sourcePropertyName, IMvxValueConverter converter = null, object converterParameter = null)
 {
     BindTextViewText <string>(activity, targetViewId, source, sourcePropertyName, converter, converterParameter);
 }
        private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter, object fallbackValue,
            Type targetType, out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
        {
            ClearAll();
            MvxBindingSingletonCache.Initialize();

            var mockSourceBindingFactory = new Mock<IMvxSourceBindingFactory>();
            Ioc.RegisterSingleton(mockSourceBindingFactory.Object);

            var mockTargetBindingFactory = new Mock<IMvxTargetBindingFactory>();
            Ioc.RegisterSingleton(mockTargetBindingFactory.Object);

            var realSourceStepFactory = new MvxSourceStepFactory();
            realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
            Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);

            var sourceText = "sourceText";
            var targetName = "targetName";
            var source = new { Value = 1 };
            var target = new { Value = 2 };
            var bindingDescription = new MvxBindingDescription
            {
                Source = new MvxPathSourceStepDescription()
                {
                    Converter = valueConverter,
                    ConverterParameter = converterParameter,
                    FallbackValue = fallbackValue,
                    SourcePropertyPath = sourceText,
                },
                Mode = MvxBindingMode.TwoWay,
                TargetName = targetName
            };

            mockSource = new MockSourceBinding();
            mockTarget = new MockTargetBinding() { TargetType = targetType };
            mockTarget.DefaultMode = MvxBindingMode.TwoWay;

            var localSource = mockSource;
            mockSourceBindingFactory
                .Setup(x => x.CreateBinding(It.IsAny<object>(), It.Is<string>(s => s == sourceText)))
                .Returns((object a, string b) => localSource);
            var localTarget = mockTarget;
            mockTargetBindingFactory
                .Setup(x => x.CreateBinding(It.IsAny<object>(), It.Is<string>(s => s == targetName)))
                .Returns((object a, string b) => localTarget);

            mockSource.TryGetValueResult = true;
            mockSource.TryGetValueValue = "TryGetValueValue";

            var request = new MvxBindingRequest(source, target, bindingDescription);
            var toTest = new MvxFullBinding(request);
            return toTest;
        }
Esempio n. 39
0
 public MvxFormsValueConverterWrapper(IMvxValueConverter source)
 {
     _Source = source;
 }