コード例 #1
0
        protected override Visual ProduceDefaultVisual(object item)
        {
            if (item == null)
            {
                return(null);
            }

            Visual defaultVisual = null;

            if (this.FallbackTemplate != null)
            {
                defaultVisual = this.ProduceVisual(item, this.FallbackTemplate);
            }
            if (defaultVisual == null)
            {
                return(base.ProduceDefaultVisual(item));
            }
            else
            {
                IAddChild textHost = defaultVisual as IAddChild;
                if (textHost != null)
                {
                    try
                    {
                        textHost.AddText(string.Format(CultureInfo.CurrentCulture, "DataTemplateNotFound: {0}", item.GetType().Name));
                    }
                    catch (ArgumentException)
                    {
                        // We can cope with failure to add text.
                    }
                }
            }

            return(defaultVisual);
        }
コード例 #2
0
        private static void AddInline([NotNull] IAddChild parent, [NotNull] Inline inline)
        {
            if (!EndsWithSpace(parent) && !StartsWithSpace(inline))
            {
                parent.AddText(" ");
            }

            parent.AddChild(inline);
        }
コード例 #3
0
ファイル: XamlFormatter.cs プロジェクト: punker76/noterium
        internal static void EscapeHtml(StringContent inp, IAddChild target)
        {
            //var parts = inp.RetrieveParts();
            //for (var i = parts.Offset; i < parts.Offset + parts.Count; i++)
            //{
            //	var part = parts.Array[i];
            //}

            target.AddText(inp.ToString().TrimEnd());
        }
コード例 #4
0
            public IAddChildMembersCallTheOtherMembersContentControl()
            {
                IAddChild add_child = (IAddChild)this;

                Assert.AreEqual(add_child_calls, 0, "1");
                add_child.AddChild(1);
                Assert.AreEqual(add_child_calls, 1, "2");
                Content = null;
                Assert.AreEqual(add_text_calls, 0, "3");
                add_child.AddText("1");
                Assert.AreEqual(add_text_calls, 1, "4");
            }
コード例 #5
0
        // Token: 0x06000693 RID: 1683 RVA: 0x00014CD4 File Offset: 0x00012ED4
        internal FrameworkObject InstantiateUnoptimizedTree()
        {
            if (!this._sealed)
            {
                throw new InvalidOperationException(SR.Get("FrameworkElementFactoryMustBeSealed"));
            }
            FrameworkObject result = new FrameworkObject(this.CreateDependencyObject());

            result.BeginInit();
            ProvideValueServiceProvider provideValueServiceProvider = null;

            FrameworkTemplate.SetTemplateParentValues(this.Name, result.DO, this._frameworkTemplate, ref provideValueServiceProvider);
            FrameworkElementFactory frameworkElementFactory = this._firstChild;
            IAddChild addChild = null;

            if (frameworkElementFactory != null)
            {
                addChild = (result.DO as IAddChild);
                if (addChild == null)
                {
                    throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[]
                    {
                        result.DO.GetType().Name
                    }));
                }
            }
            while (frameworkElementFactory != null)
            {
                if (frameworkElementFactory._text != null)
                {
                    addChild.AddText(frameworkElementFactory._text);
                }
                else
                {
                    FrameworkObject childFrameworkObject = frameworkElementFactory.InstantiateUnoptimizedTree();
                    this.AddNodeToParent(result.DO, childFrameworkObject);
                }
                frameworkElementFactory = frameworkElementFactory._nextSibling;
            }
            result.EndInit();
            return(result);
        }
コード例 #6
0
        public void IAddChildTest()
        {
            Decorator d         = new Decorator();
            IAddChild add_child = (IAddChild)d;
            UIElement b         = new UIElement();

            add_child.AddChild(b);
            Assert.AreSame(d.Child, b, "1");
            try {
                add_child.AddChild(new UIElement());
                Assert.Fail("2");
            } catch (ArgumentException ex) {
                Assert.AreEqual(ex.Message, "'System.Windows.Controls.Decorator' already has a child and cannot add 'System.Windows.UIElement'. 'System.Windows.Controls.Decorator' can accept only one child.", "3");
            }
            d.Child = null;
            try {
                add_child.AddChild(new DrawingVisual());
                Assert.Fail("4");
            } catch (ArgumentException ex) {
                Assert.AreEqual(ex.Message, "Parameter is unexpected type 'System.Windows.Media.DrawingVisual'. Expected type is 'System.Windows.UIElement'.\r\nParameter name: value", "5");
            }
            d.Child = new UIElement();
            try {
                add_child.AddChild(new DrawingVisual());
                Assert.Fail("5");
            } catch (ArgumentException ex) {
                Assert.AreEqual(ex.Message, "Parameter is unexpected type 'System.Windows.Media.DrawingVisual'. Expected type is 'System.Windows.UIElement'.\r\nParameter name: value", "6");
            }
            d.Child = null;
            try {
                add_child.AddChild(null);
                Assert.Fail("7");
            } catch (NullReferenceException) {
            }
            try {
                add_child.AddText("1");
                Assert.Fail("8");
            } catch (ArgumentException ex) {
                Assert.AreEqual(ex.Message, "'1' text cannot be added because text is not valid in this element.", "9");
            }
        }
コード例 #7
0
        /// <summary>
        /// Adds a value to the end of a collection.
        /// </summary>
        public static void AddToCollection(Type collectionType, object collectionInstance, XamlPropertyValue newElement)
        {
            IAddChild addChild = collectionInstance as IAddChild;

            if (addChild != null)
            {
                if (newElement is XamlTextValue)
                {
                    addChild.AddText((string)newElement.GetValueFor(null));
                }
                else
                {
                    addChild.AddChild(newElement.GetValueFor(null));
                }
            }
            else if (collectionInstance is IDictionary)
            {
                object val = newElement.GetValueFor(null);
                object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
                if (key == null || key == "")
                {
                    if (val is Style)
                    {
                        key = ((Style)val).TargetType;
                    }
                }
                if (key == null || (key as string) == "")
                {
                    key = val;
                }
                ((IDictionary)collectionInstance).Add(key, val);
            }
            else
            {
                collectionType.InvokeMember(
                    "Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
                    null, collectionInstance,
                    new object[] { newElement.GetValueFor(null) },
                    CultureInfo.InvariantCulture);
            }
        }
コード例 #8
0
ファイル: XamlFormatter.cs プロジェクト: punker76/noterium
        /// <summary>
        /// Writes the inline list to the given parent as HTML code.
        /// </summary>
        private void InlinesToXaml(IAddChild parent, Inline inline, CommonMarkSettings settings, Stack <InlineStackEntry> stack)
        {
            var  uriResolver     = settings.UriResolver;
            bool withinLink      = false;
            bool stackWithinLink = false;
            bool trackPositions  = settings.TrackSourcePosition;

            IAddChild blockParent = parent;

            if (blockParent is ListItem || blockParent is Section || blockParent is TableCell)
            {
                Paragraph p = new Paragraph();
                blockParent.AddChild(p);
                blockParent = p;
            }

            while (inline != null)
            {
                var       visitChildren = false;
                IAddChild lastParent    = null;

                switch (inline.Tag)
                {
                case InlineTag.String:
                    //if (inline.LiteralContent.StartsWith("[ ]") || inline.LiteralContent.StartsWith("[x]"))
                    //{
                    //	CheckBox bt = new CheckBox
                    //	{
                    //		IsChecked = inline.LiteralContent.Contains("[x]"),
                    //		Content = inline.LiteralContent.Substring(2),
                    //		Tag = _checkBoxNumber
                    //	};
                    //	bt.CommandParameter = bt;
                    //	bt.Command = CheckBoxCheckedCommand;
                    //	bt.Style = TodoCheckBoxStyle;
                    //	blockParent.AddChild(new BlockUIContainer(bt));
                    //	_checkBoxNumber++;
                    //}
                    //else
                    blockParent.AddText(inline.LiteralContent);
                    break;

                case InlineTag.LineBreak:
                    blockParent.AddChild(new LineBreak());
                    break;

                case InlineTag.SoftBreak:
                    if (settings.RenderSoftLineBreaksAsLineBreaks)
                    {
                        blockParent.AddChild(new LineBreak());
                    }
                    break;

                case InlineTag.Code:

                    Span codeSpan = new Span(new Run(inline.LiteralContent));
                    if (InlineCodeStyle != null)
                    {
                        codeSpan.Style = InlineCodeStyle;
                    }

                    blockParent.AddChild(codeSpan);

                    break;

                case InlineTag.RawHtml:
                    // cannot output source position for HTML blocks
                    blockParent.AddText(inline.LiteralContent);
                    break;

                case InlineTag.Link:
                    if (withinLink)
                    {
                        //parent.Write('[');
                        //stackLiteral = "]";
                        stackWithinLink = true;
                        visitChildren   = true;
                    }
                    else
                    {
                        Hyperlink hyperlink = new Hyperlink();

                        if (LinkStyle != null)
                        {
                            hyperlink.Style = LinkStyle;
                        }

                        string url = inline.TargetUrl;
                        if (uriResolver != null)
                        {
                            url = uriResolver(inline.TargetUrl);
                        }

                        hyperlink.CommandParameter = url;
                        if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                        {
                            hyperlink.NavigateUri      = new Uri(url);
                            hyperlink.RequestNavigate += (sender, e) =>
                            {
                                System.Diagnostics.Process.Start(e.Uri.ToString());
                            };
                        }
                        else
                        {
                            hyperlink.Command = HyperlinkCommand;
                        }

                        if (inline.LiteralContent.Length > 0)
                        {
                            hyperlink.ToolTip = inline.LiteralContent;
                        }

                        if (trackPositions)
                        {
                            PrintPosition(hyperlink, inline);
                        }

                        if (!(blockParent is Hyperlink))
                        {
                            blockParent.AddChild(hyperlink);
                        }

                        lastParent  = blockParent;
                        blockParent = hyperlink;

                        visitChildren   = true;
                        stackWithinLink = true;
                    }
                    break;

                case InlineTag.Image:
                    HandleImage(inline, parent);

                    break;

                case InlineTag.Strong:
                    Bold bold = new Bold();
                    blockParent.AddChild(bold);
                    lastParent  = blockParent;
                    blockParent = bold;

                    if (trackPositions)
                    {
                        PrintPosition(bold, inline);
                    }

                    stackWithinLink = withinLink;
                    visitChildren   = true;
                    break;

                case InlineTag.Emphasis:
                    Italic italic = new Italic();
                    blockParent.AddChild(italic);
                    lastParent  = blockParent;
                    blockParent = italic;

                    if (trackPositions)
                    {
                        PrintPosition(italic, inline);
                    }

                    visitChildren   = true;
                    stackWithinLink = withinLink;
                    break;

                case InlineTag.Strikethrough:
                    Span strikethroughSpan = new Span();
                    strikethroughSpan.TextDecorations = TextDecorations.Strikethrough;

                    blockParent.AddChild(strikethroughSpan);
                    lastParent  = blockParent;
                    blockParent = strikethroughSpan;

                    if (trackPositions)
                    {
                        PrintPosition(strikethroughSpan, inline);
                    }

                    visitChildren   = true;
                    stackWithinLink = withinLink;
                    break;

                case InlineTag.Placeholder:
                    // the slim formatter will treat placeholders like literals, without applying any further processing

                    //if (blockParent is ListItem)
                    //	blockParent.AddChild(new Paragraph(new Run("Placeholder")));
                    //else
                    //	blockParent.AddText("Placeholder");

                    //visitChildren = false;

                    //TODO: Handle todo-list items here
                    break;

                default:
                    throw new CommonMarkException("Inline type " + inline.Tag + " is not supported.", inline);
                }

                if (visitChildren)
                {
                    stack.Push(new InlineStackEntry(lastParent, inline.NextSibling, withinLink));

                    withinLink = stackWithinLink;
                    inline     = inline.FirstChild;
                }
                else if (inline.NextSibling != null)
                {
                    inline = inline.NextSibling;
                }
                else
                {
                    inline = null;
                }

                while (inline == null && stack.Count > 0)
                {
                    var entry = stack.Pop();

                    blockParent = entry.Parent;
                    inline      = entry.Target;
                    withinLink  = entry.IsWithinLink;
                }
            }
        }
コード例 #9
0
        void IAddChild.AddText(string text)
        {
            IAddChild actualAddChild = ActualBinding;

            actualAddChild.AddText(text);
        }
コード例 #10
0
        // Token: 0x06000691 RID: 1681 RVA: 0x00014908 File Offset: 0x00012B08
        internal DependencyObject InstantiateTree(UncommonField <HybridDictionary[]> dataField, DependencyObject container, DependencyObject parent, List <DependencyObject> affectedChildren, ref List <DependencyObject> noChildIndexChildren, ref FrugalStructList <ChildPropertyDependent> resourceDependents)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstBegin);
            FrameworkElement frameworkElement = container as FrameworkElement;
            bool             flag             = frameworkElement != null;
            DependencyObject dependencyObject = null;

            if (this._text != null)
            {
                IAddChild addChild = parent as IAddChild;
                if (addChild == null)
                {
                    throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[]
                    {
                        parent.GetType().Name
                    }));
                }
                addChild.AddText(this._text);
            }
            else
            {
                dependencyObject = this.CreateDependencyObject();
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstEnd);
                FrameworkObject frameworkObject = new FrameworkObject(dependencyObject);
                Visual3D        visual3D        = null;
                bool            flag2           = false;
                if (!frameworkObject.IsValid)
                {
                    visual3D = (dependencyObject as Visual3D);
                    if (visual3D != null)
                    {
                        flag2 = true;
                    }
                }
                bool isFE = frameworkObject.IsFE;
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeBeginInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (StyleHelper.HasResourceDependentsForChild(this._childIndex, ref resourceDependents))
                    {
                        frameworkObject.HasResourceReference = true;
                    }
                    FrameworkElementFactory.UpdateChildChains(this._childName, this._childIndex, isFE, frameworkObject.FE, frameworkObject.FCE, affectedChildren, ref noChildIndexChildren);
                    FrameworkElementFactory.NewNodeStyledParentProperty(container, flag, isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (this._childIndex != -1)
                    {
                        StyleHelper.CreateInstanceDataForChild(dataField, container, dependencyObject, this._childIndex, this._frameworkTemplate.HasInstanceValues, ref this._frameworkTemplate.ChildRecordFromChildIndex);
                    }
                    if (this.HasLoadedChangeHandler)
                    {
                        BroadcastEventHelper.AddHasLoadedChangeHandlerFlagInAncestry(dependencyObject);
                    }
                }
                else if (this._childName != null)
                {
                    affectedChildren.Add(dependencyObject);
                }
                else
                {
                    if (noChildIndexChildren == null)
                    {
                        noChildIndexChildren = new List <DependencyObject>(4);
                    }
                    noChildIndexChildren.Add(dependencyObject);
                }
                if (container == parent)
                {
                    TemplateNameScope value = new TemplateNameScope(container);
                    NameScope.SetNameScope(dependencyObject, value);
                    if (flag)
                    {
                        frameworkElement.TemplateChild = frameworkObject.FE;
                    }
                    else
                    {
                        FrameworkElementFactory.AddNodeToLogicalTree((FrameworkContentElement)parent, this._type, isFE, frameworkObject.FE, frameworkObject.FCE);
                    }
                }
                else
                {
                    this.AddNodeToParent(parent, frameworkObject);
                }
                if (!flag2)
                {
                    StyleHelper.InvalidatePropertiesOnTemplateNode(container, frameworkObject, this._childIndex, ref this._frameworkTemplate.ChildRecordFromChildIndex, false, this);
                }
                else
                {
                    for (int i = 0; i < this.PropertyValues.Count; i++)
                    {
                        if (this.PropertyValues[i].ValueType != PropertyValueType.Set)
                        {
                            throw new NotSupportedException(SR.Get("Template3DValueOnly", new object[]
                            {
                                this.PropertyValues[i].Property
                            }));
                        }
                        object    obj       = this.PropertyValues[i].ValueInternal;
                        Freezable freezable = obj as Freezable;
                        if (freezable != null && !freezable.CanFreeze)
                        {
                            obj = freezable.Clone();
                        }
                        MarkupExtension markupExtension = obj as MarkupExtension;
                        if (markupExtension != null)
                        {
                            ProvideValueServiceProvider provideValueServiceProvider = new ProvideValueServiceProvider();
                            provideValueServiceProvider.SetData(visual3D, this.PropertyValues[i].Property);
                            obj = markupExtension.ProvideValue(provideValueServiceProvider);
                        }
                        visual3D.SetValue(this.PropertyValues[i].Property, obj);
                    }
                }
                for (FrameworkElementFactory frameworkElementFactory = this._firstChild; frameworkElementFactory != null; frameworkElementFactory = frameworkElementFactory._nextSibling)
                {
                    frameworkElementFactory.InstantiateTree(dataField, container, dependencyObject, affectedChildren, ref noChildIndexChildren, ref resourceDependents);
                }
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeEndInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                }
            }
            return(dependencyObject);
        }