Beispiel #1
0
 public void Add(LinkSpan lb)
 {
     this.Inlines.Add(lb);
 }
Beispiel #2
0
        private LinkSpan __RecContentMarkupToWPF(XElement root)
        {
            LinkSpan ret = null; //the returnee

            //ALIASES
            //<word>value</word> is alias for <link Target="value" Nest="2"><text>value</text></link>
            if (root.Name.LocalName == "word")
            {
                var textEl = root;
                string linkVal = (root.Attribute("Target") == null ? root.Value : root.Attribute("Target").Value);
                textEl.Name = XName.Get("text");
                root = new XElement("link");
                root.SetAttributeValue("Target", linkVal);
                root.SetAttributeValue("Nest", "2");
                root.Add(textEl);

            }
            else if (root.Name.LocalName == "h1")
            //<h1>value</h1> is alias for <paragraph><text FontSize="32">value</text><br /></paragraph>
            {
                var val = root.Value;
                var attributes = root.Attributes();
                root = new XElement("paragraph");
                var valText = new XElement("text", val);
                valText.SetAttributeValue("FontSize", "32");
                //root.Value = val + "<br />";
                foreach (var attribute in attributes)
                    valText.SetAttributeValue(attribute.Name, attribute.Value);
                root.Add(valText);//, new XElement("br"));
            }
            else if (root.Name.LocalName == "h2")
            //<h2>value</h2> is alias for <paragraph><br /><text FontSize="24">value</text><br /></paragraph>
            {
                var val = root.Value;
                var attributes = root.Attributes();
                root = new XElement("paragraph");
                var valText = new XElement("text", val);
                valText.SetAttributeValue("FontSize", "24");
                //root.Value = val + "<br />";
                foreach (var attribute in attributes)
                    valText.SetAttributeValue(attribute.Name, attribute.Value);
                root.Add(new XElement("br"), valText, new XElement("br"));
            }

            //GET GLOBAL FORMATTING ATTRIBUTES
            int fontSize = -1;
            if (root.Attribute("FontSize") != null)
            {
                fontSize = Int32.Parse(root.Attribute("FontSize").Value);
            }
            Brush colour = null;
            if (root.Attribute("Colour") != null)
            {
                colour = (Brush)new BrushConverter().ConvertFromString(root.Attribute("Colour").Value);
            }

            switch (root.Name.LocalName)
            {

                case "paragraph":

                    var paragraphPanel = new LinkSpan();

                    //foreach (var l in root.Elements())
                    //{ paragraphPanel.Inlines.Add(__RecContentMarkupToWPF(l)); }
                    paragraphPanel.Inlines.AddRange(__DeNode(root));

                    ret = paragraphPanel;
                    break;
                case "link":
                    var linkInline = new LinkSpan();
                    if (root.Attribute("Target") == null)
                    {
                        linkInline.Link = new Link { LinksTo = null };
                        //foreach (var l in root.Elements())
                        //{ linkInline.Add(__RecContentMarkupToWPF(l)); }
                        linkInline.Inlines.AddRange(__DeNode(root));
                    }
                    else
                    {
                        int nest = 0;
                        if (root.Attribute("Nest") != null)
                            nest = Int32.Parse(root.Attribute("Nest").Value);

                        //make border
                        Border blockBorder = new Border();
                        blockBorder.BorderThickness = new Thickness(1);
                        blockBorder.Background = Brushes.Black;

                        LinkBlock MarginBlock = new LinkBlock();

                        if (nest == 0)
                            MarginBlock.Background = SENTENCE_BRUSH_COLOUR; //This should change
                        else if (nest == 1)
                            MarginBlock.Background = FRAGMENT_BRUSH_COLOUR;
                        else if (nest == 2)
                            MarginBlock.Background = WORD_BRUSH_COLOUR;
                        MarginBlock.MouseLeftButtonUp += new MouseButtonEventHandler(_OnClickBlock);
                        MarginBlock.Link = new Link { LinksTo = root.Attribute("Target").Value };
                        SetPadding(MarginBlock, 5);

                        MarginBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                        //foreach (var l in root.Elements())
                        //{ MarginBlock.Inlines.Add(__RecContentMarkupToWPF(l)); }
                        MarginBlock.Inlines.AddRange(__DeNode(root));
                        blockBorder.Child = MarginBlock;
                        linkInline.Add(blockBorder);
                    }

                    ret = linkInline;
                    break;
                case "text":
                    var textLinkSpan = new LinkSpan();
                    textLinkSpan.FontFamily = new FontFamily("ClearType");
                    textLinkSpan.FontSize = 16d;
                    if (root.Value != null)
                        textLinkSpan.Add(new Run { Text = root.Value });
                    textLinkSpan.Link = new Link { LinksTo = (root.Attribute("WordLinksTo") == null ? null : root.Attribute("WordLinksTo").Value) };
                    textLinkSpan.BaselineAlignment = BaselineAlignment.Center;
                    ret = textLinkSpan;
                    break;
                case "img":
                    var imgLinkSpan = new LinkSpan();
                    Image img = new Image();
                    img.ClipToBounds = true;
                    img.Stretch = Stretch.Uniform;
                    SetMargin(img, 20);
                    if (File.Exists(PamyaDeck.Instance.CurrentDeckFolder + @"\" + root.Value))
                        img.Source = new BitmapImage(new Uri(PamyaDeck.Instance.CurrentDeckFolder + @"\" + root.Value));
                    imgLinkSpan.Add(img);
                    ret = imgLinkSpan;
                    break;
                case "br":
                    var seperatorLinkSpan = new LinkSpan();
                    seperatorLinkSpan.Add(new LineBreak());
                    ret = seperatorLinkSpan;
                    break;
                default: return null;
            }

            //set Global attributes
            if (fontSize > -1)
                ret.FontSize = fontSize;
            if (colour != null)
                ret.Foreground = colour;

            return ret;
        }