Exemple #1
0
        public void ApplyBinding(
            BindingExpression bindingExpression,
            object activity,
            string dataContextPropertyOnActivity,
            IValueConverter converter,
            List <Action> unbindActions)
        {
#if NETSTANDARD
            PropertyInfo targetProperty = bindingExpression.View.GetType().GetRuntimeProperty(bindingExpression.Target);
#else
            PropertyInfo targetProperty = bindingExpression.View.GetType().GetProperty(bindingExpression.Target);
#endif
            var localRemoveActions = new List <Action>();

            string sourcePath = bindingExpression.Source?.Trim();
            string path       = bindingExpression.Path?.Trim();

            object   dataContext;
            string[] pathSplit;

            MarkupExtensionInfo extensionInfo
                = markupExtensionUtil.CreateMarkupExtensionInfo(sourcePath);
            if (extensionInfo == null)
            {
                pathSplit   = GetPathSplit(sourcePath, path, dataContextPropertyOnActivity);
                dataContext = activity;
            }
            else
            {
                dataContext = RetrieveExtensionValue(extensionInfo);
                pathSplit   = GetPathSplit(null, path, null);
            }

            Bind(bindingExpression, dataContext, dataContext, pathSplit, converter, targetProperty, localRemoveActions, unbindActions, 0);
        }
Exemple #2
0
        object RetrieveExtensionValue(MarkupExtensionInfo extensionInfo)
        {
            if (iocContainer == null)
            {
                iocContainer = Dependency.Resolve <IContainer>();
            }

            var extension = RetrieveExtension(extensionInfo);
            var result    = extension.ProvideValue(iocContainer);

            return(result);
        }
Exemple #3
0
        public MarkupExtensionInfo CreateMarkupExtensionInfo(string text)
        {
            if (text == null)
            {
                return(null);
            }

            var match = markupExtensionRegex.Match(text);

            if (match.Success)
            {
                var    groups        = match.Groups;
                string extension     = groups["Extension"]?.Value;
                string parameters    = groups["Parameters"]?.Value ?? string.Empty;
                var    parameterList = parameters.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var    result        = new MarkupExtensionInfo(extension, parameterList);

                return(result);
            }

            return(null);
        }
Exemple #4
0
        public IMarkupExtension RetrieveExtension(MarkupExtensionInfo extensionInfo)
        {
            var extensionRegistry = Dependency.Resolve <IMarkupExtensionRegistry>();

            var retrievedItem = extensionRegistry.TryGetExtensionCreationFunc(
                extensionInfo.ExtensionTypeName,
                out Func <object[], IMarkupExtension> creationFunc) &&
                                creationFunc != null;

            if (!retrievedItem)
            {
                throw new BindingException("Unable to resolve MarkupExtension. " + extensionInfo.ExtensionTypeName);
            }

            try
            {
                var result = creationFunc(extensionInfo.Parameters);
                return(result);
            }
            catch (Exception ex)
            {
                throw new BindingException("Unable to create MarkupExtension. " + extensionInfo.ExtensionTypeName, ex);
            }
        }