internal static void LoadComponent(FrameworkElement control, Element node, bool isDesignMode = false, Action <int, FrameworkElement> ElementCreatedAtLine = null, string xml = null)
        {
            var builder = new UIBuilder
            {
                _rootNode     = node,
                DataContext   = control,
                Caller        = control,
                _isDesignMode = isDesignMode,
                XmlString     = xml
            };

            if (ElementCreatedAtLine != null)
            {
                builder.ElementCreatedAtLine += ElementCreatedAtLine;
            }

            var subControl = builder.BuildNode(builder._rootNode, control);

            var subControlAsFrameworkElement = subControl as FrameworkElement;

            if (subControlAsFrameworkElement == null)
            {
                throw new InvalidOperationException("ControlFirstItemMustBeHTMLElement");
            }

            InitDOM(control);
            control.AddLogicalChild(subControlAsFrameworkElement);
        }
Exemple #2
0
        protected virtual FrameworkElement CreateItemRendererControlForStringContent(string content)
        {
            var textBlock = UIBuilder.Create <TextBlock>();

            textBlock.InnerHTML = content;

            return(textBlock);
        }
        internal void ApplyTemplate()
        {
            var template = Template ?? DefaultTemplate;

            if (template == null)
            {
                return;
            }

            UIBuilder.BuildControlTemplate(template, this);
        }
Exemple #4
0
        protected virtual void Render()
        {
            if (ItemsSource == null)
            {
                return;
            }

            var records = ItemsSource as IEnumerable;

            if (records == null)
            {
                throw ItemSourceMustbe_Enumerable();
            }

            ClearItems();

            var itemTemplate = ItemTemplate;

            foreach (var itemData in records)
            {
                FrameworkElement item = null;
                if (itemTemplate != null)
                {
                    var fe = new FrameworkElement
                    {
                        DataContext = itemData
                    };

                    UIBuilder.LoadComponent(fe, ItemTemplate.Root);

                    item = fe.GetLogicalChildAt(0);
                }
                else
                {
                    item = CreateItemRendererControlForStringContent(itemData?.ToString());
                }

                var data = itemData;
                item.On("click", () => { ItemClicked?.Invoke(data); });

                ConnectItem(item);
            }

            AfterRenderCompleted?.Invoke();
        }
        internal static void BuildControlTemplate(Template xmlTemplate, FrameworkElement control)
        {
            var builder = new UIBuilder
            {
                _rootNode           = xmlTemplate.Root,
                DataContext         = control,
                Caller              = control,
                _isBuildingTemplate = true
            };

            var subControl = builder.BuildNode(builder._rootNode, control);

            var subControlAsFrameworkElement = subControl as FrameworkElement;

            if (subControlAsFrameworkElement == null)
            {
                throw new InvalidOperationException("TemplateControlFirstItemMustBeHTMLElement");
            }

            control._root = subControlAsFrameworkElement._root;
            control.AddVisualChild(subControlAsFrameworkElement);
        }