コード例 #1
0
        private async Task <IDataTemplate> BuildDataTemplateAsync(IMarkupNode node,
                                                                  Type?dataContextType,
                                                                  Dictionary <String, String> nameSpaceAssemblySearch,
                                                                  IVisualLineage visualLineage,
                                                                  ApplyVisualStyles applyStyles)
        {
            if (node.ChildrenCount != 1)
            {
                var visuals = new List <IVisualElement>();

                foreach (var childNode in node.Children)
                {
                    var visual = await GetVisualAsync(childNode, dataContextType,
                                                      nameSpaceAssemblySearch, visualLineage, applyStyles).ConfigureAwait(false);

                    visuals.Add(visual);
                }

                return(new MultiDataTemplate(_visualBootstrapper, dataContextType, visuals));
            }

            var onlyChild = node.Children.First();

            switch (onlyChild.Name)
            {
            case nameof(MultiDataTemplate):
                var dataBindings = (await _bindingBuilder.GetBindingsDictionaryAsync(node,
                                                                                     dataContextType, nameSpaceAssemblySearch)).Values.OfType <IDataBinding>();

                dataContextType = _bindingBuilder.InferDataContextTypeFromBindings(dataBindings,
                                                                                   dataContextType);
                return(await BuildDataTemplateAsync(onlyChild, dataContextType,
                                                    nameSpaceAssemblySearch, visualLineage, applyStyles).ConfigureAwait(false));

            case nameof(DataTemplate):
                return(await BuildDataTemplateAsync(onlyChild, dataContextType,
                                                    nameSpaceAssemblySearch, visualLineage, applyStyles).ConfigureAwait(false));

            default:
                var visualContent = await GetVisualAsync(onlyChild, dataContextType,
                                                         nameSpaceAssemblySearch, visualLineage, applyStyles).ConfigureAwait(false);

                visualLineage.AssertPopVisual(visualContent);
                return(new DataTemplate(_visualBootstrapper, dataContextType, visualContent));
            }
        }
コード例 #2
0
        private static IEnumerable <IVisualElement> GetSelectableVisualsImpl(IVisualElement rootVisual,
                                                                             AndStyleSelector selectors,
                                                                             IVisualLineage visualLineage,
                                                                             Int32 selectorIndex)
        {
            var currentVisual = rootVisual;

            for (var c = selectorIndex; c < selectors.Count; c++)
            {
                var currentSelector = selectors[c];

                switch (currentSelector)
                {
                case CombinatorSelector combinator:
                    switch (combinator.Combinator)
                    {
                    case Combinator.Invalid:
                    case Combinator.None:
                        throw new InvalidOperationException();

                    case Combinator.Descendant:
                        break;

                    case Combinator.Child:
                        if (!(currentVisual is IVisualContainer container))
                        {
                            yield break;
                        }

                        foreach (var childVisual in container.Children.GetAllChildren())
                        {
                            visualLineage.PushVisual(childVisual);

                            var selectableChildren = GetSelectableVisualsImpl(childVisual,
                                                                              selectors, visualLineage, c + 1);

                            foreach (var selectable in selectableChildren)
                            {
                                yield return(selectable);
                            }

                            visualLineage.AssertPopVisual(childVisual);
                        }

                        break;


                    case Combinator.GeneralSibling:
                        break;

                    case Combinator.AdjacentSibling:

                        var nextSibling = visualLineage.GetNextSibling();

                        if (nextSibling != null)
                        {
                            visualLineage.PushVisual(nextSibling);

                            var selectableSiblings = GetSelectableVisualsImpl(nextSibling,
                                                                              selectors, visualLineage, c + 1);

                            foreach (var selectable in selectableSiblings)
                            {
                                yield return(selectable);
                            }

                            visualLineage.AssertPopVisual(nextSibling);
                        }

                        break;

                    case Combinator.Column:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    break;

                case VisualStateSelector stateSelector:
                    if (IsVisualSelectable(currentVisual, stateSelector.BaseSelector, visualLineage))
                    {
                    }
                    goto default;

                default:
                    if (!IsVisualSelectable(currentVisual, currentSelector, visualLineage))
                    {
                        yield break;
                    }

                    if (c == selectors.Count - 1)
                    {
                        yield return(currentVisual);
                    }
                    break;
                }
            }
        }
コード例 #3
0
        private async Task <IContentVisual> BuildContentVisualAsync(IMarkupNode node,
                                                                    Type?dataContextType,
                                                                    Dictionary <String, String> nameSpaceAssemblySearch,
                                                                    Type visualType,
                                                                    IVisualLineage visualLineage,
                                                                    ApplyVisualStyles applyStyles)
        {
            IVisualElement?contentVisual = null;

            //-------------------------------
            var contentContainer = _visualBootstrapper.Instantiate <IContentVisual>(visualType)
                                   ?? throw new InvalidOperationException();

            //await applyStyles(contentContainer, node, visualLineage, this);
            //-------------------------------

            visualLineage.PushVisual(contentContainer);

            switch (node.ChildrenCount)
            {
            case 1:
            {
                var currentNode = node[0];
                var childObjRes = await InflateChildAsync(currentNode, contentContainer,
                                                          dataContextType, nameSpaceAssemblySearch, visualLineage, applyStyles)
                                  .ConfigureAwait(false);

                if (childObjRes.ChildType == ChildNodeType.ChildVisual &&
                    childObjRes.Child is IVisualElement childVisual)
                {
                    contentVisual = childVisual;
                }

                else if (childObjRes.ChildType == ChildNodeType.PropertyValue &&
                         childObjRes.VisualProperty is { } prop)
                {
                    //Object oContentContainer = contentContainer;
                    prop.SetPropertyValue(ref contentContainer, childObjRes.Child);
                    //prop.SetValue(contentContainer, childObjRes.Child, null);
                }

                break;
            }

            case 0:
            {
                if (!node.TryGetAttributeValue(nameof(IContentContainer.Content), out var textContent))
                {
                    textContent = node.InnerText;
                }

                if (!String.IsNullOrEmpty(textContent))
                {
                    // zb <button>TEXT</button> etc
                    contentVisual = new Label(_visualBootstrapper)
                    {
                        Text = textContent !
                    };
                    visualLineage.PushVisual(contentVisual);
                }

                break;
            }

            default:
                throw new NotImplementedException();
            }


            contentContainer !.Content = contentVisual;

            if (contentVisual != null)
            {
                visualLineage.AssertPopVisual(contentVisual);
            }


            return(contentContainer);
        }
コード例 #4
0
        public async Task ApplyStylesToVisualAsync(IVisualElement visual,
                                                   IAttributeDictionary attributeDictionary,
                                                   IVisualLineage visualLineage,
                                                   IViewInflater viewInflater)
        {
            await _appliedStyleBuilder.ApplyVisualStylesAsync(visual, attributeDictionary,
                                                              visualLineage, viewInflater);

            return;

            var omgStyle = await _styleProvider.GetStyleForVisualAsync(visual, attributeDictionary);

            if (omgStyle != null)
            {
            }

            if (attributeDictionary.TryGetAttributeValue("class", out var className))
            {
                await ApplyStylesToVisualAsync(visual, className, visualLineage);

                return;
            }

            if (attributeDictionary.TryGetAttributeValue("Style", out var styleName))
            {
                var style = await _styleProvider.GetStyleByNameAsync(styleName);

                if (style == null)
                {
                    return;
                }

                //var applyingRules = new StyledVisualWorker(style, _propertyProvider, _visualBootstrapper);

                //applyingRules.TrySetVisualStyle(visual, style);

                //if (applyingRules.TryGetVisualTemplate(out var visualTemplate) &&
                //    visualTemplate is DeferredVisualTemplate deferred)
                if (TryGetVisualTemplate(style, out var visualTemplate) &&
                    visualTemplate is DeferredVisualTemplate deferred)
                {
                    //var contentVisual = await viewInflater.GetVisualAsync(deferred.MarkupNode,
                    //    visual.GetType(), visualLineage, applyingRules.ApplyStylesToVisualAsync);

                    var contentVisual = await viewInflater.GetVisualAsync(deferred.MarkupNode,
                                                                          visual.GetType(), visualLineage, _appliedStyleBuilder.ApplyVisualStylesAsync);

                    visual.Template = new VisualTemplate
                    {
                        Content = contentVisual
                    };

                    //control template's data context should be the control being templated....?
                    if (contentVisual is IBindableElement bindable)
                    {
                        bindable.DataContext = visual;
                    }

                    visualLineage.AssertPopVisual(contentVisual);

                    _appliedStyleBuilder.BuildAppliedStyle(style, visual, visualLineage);
                }
                else
                {
                    await _appliedStyleBuilder.ApplyVisualStylesAsync(visual, attributeDictionary, visualLineage);

                    //applyingRules.ApplyStyleValuesToVisual(visual, attributeDictionary, visualLineage);
                }
            }
        }