コード例 #1
0
        private void ParseHyperlinks()
        {
            var style   = HyperlinkStyle;
            var text    = Text;
            var matches = HyperlinkRegex.Matches(text);

            if (matches.Count == 0)
            {
                return;
            }

            Inlines.Clear();
            var lastIndex = 0;

            foreach (Match match in matches)
            {
                Inlines.Add(text.Substring(lastIndex, match.Index - lastIndex));
                lastIndex = match.Index + match.Length;
                var run = new Run(match.Value)
                {
                    Style = style
                };
                run.MouseDown += RunOnMouseDown;
                Inlines.Add(run);
            }
            Inlines.Add(text.Substring(lastIndex));
        }
コード例 #2
0
        private void UpdateHighlightEffect()
        {
            if (string.IsNullOrEmpty(HighlightedText))
            {
                return;
            }

            var allText = GetCompleteText();

            Inlines.Clear();

            var indexOfHighlightString = allText.IndexOf(HighlightedText, StringComparison.InvariantCultureIgnoreCase);

            if (indexOfHighlightString < 0)
            {
                Inlines.Add(allText);
            }
            else
            {
                Inlines.Add(allText.Substring(0, indexOfHighlightString));
                Inlines.Add(new Run
                {
                    Text       = allText.Substring(indexOfHighlightString, HighlightedText.Length),
                    Foreground = Brushes.White,
                    Background = Brushes.OrangeRed
                });
                Inlines.Add(allText.Substring(indexOfHighlightString + HighlightedText.Length));
            }
        }
コード例 #3
0
ファイル: TextBlock.xaml.cs プロジェクト: tmstar/emoji.wpf
        private void TextChangedCallback(String text)
        {
            if (m_recursion_guard)
            {
                return;
            }

            m_recursion_guard = true;
            try
            {
                Inlines.Clear();
                int pos = 0;
                foreach (Match m in EmojiData.MatchMultiple.Matches(text))
                {
                    Inlines.Add(text.Substring(pos, m.Index - pos));
                    Inlines.Add(new EmojiInline()
                    {
                        FallbackBrush = Foreground,
                        Text          = text.Substring(m.Index, m.Length),
                        FontSize      = FontSize,
                    });

                    pos = m.Index + m.Length;
                }
                Inlines.Add(text.Substring(pos));
            }
            finally
            {
                m_recursion_guard = false;
            }
        }
コード例 #4
0
        /// <summary>A method that converts the message text line by line into Run and adds them to the Inlines collection.</summary>
        /// <param name="message">Text to add to Inlines.</param>
        protected void DebugAddedText(string message)
        {
            if (Inlines == null || !IsOutputsText)
            {
                return;
            }

            string[] lines = message.Split(LineSeparators, StringSplitOptions.None);
            if (lines.Length == 0)
            {
                return;
            }

            if (Inlines.Count == 0)
            {
                Inlines.Add(new Run(lines[0]));
            }
            else
            {
                ((Run)Inlines.ElementAt(Inlines.Count - 1)).Text += lines[0];
            }

            for (int i = 1; i < lines.Length; i++)
            {
                ((Run)Inlines.ElementAt(Inlines.Count - 1)).Text += Environment.NewLine;

                Run run = new Run(lines[i]);
                Inlines.Add(run);

                if (Inlines.Count % HighlightedInterval == 0)
                {
                    run.Foreground = Highlighted;
                }
            }
        }
コード例 #5
0
        public FormatTheText()
        {
            Title = "Format the Text";

            TextBlock txt = new TextBlock();

            txt.FontSize = 32;                  // 24
            points
            txt.Inlines.Add("This is some ");

            txt.Inlines.Add(new Italic(new Run
                                           ("italic")));
            txt.Inlines.Add(" text, and this is
     some ");
            txt.Inlines.Add(new Bold(new Run
                                         ("bold")));
            txt.Inlines.Add(" text, and let's cap
     it off with some ");
            txt.Inlines.Add(new Bold(new Italic
                                         (new Run("bold italic"))));
            txt.Inlines.Add(" text.");
            txt.TextWrapping = TextWrapping.Wrap;

            Content = txt;
        }
コード例 #6
0
        private void HandlePropertyChanged()
        {
            var sourceText = Text;

            if (sourceText.Length == 0)
            {
                return;
            }

            this.Inlines.Clear();

            var startIndex = PartialColoredStart;
            var length     = PartialColoredLength;

            if (length <= 0 || startIndex < 0 || sourceText.Length <= startIndex)
            {
                Inlines.Add(sourceText);
            }
            else
            {
                Inlines.Add(sourceText.Substring(0, startIndex));
                Inlines.Add(new Run()
                {
                    Text       = sourceText.Substring(startIndex, length),
                    Foreground = PartialColoredForeground,
                    //FontWeight = FontWeights.Bold,
                    Background = PartialColoredBackground
                });
                Inlines.Add(sourceText.Substring(startIndex + length));
            }
        }
コード例 #7
0
        private void Update()
        {
            if (!IsLoaded || !dirty)
            {
                return;
            }

            var bbcode = BbCode;

            Inlines.Clear();

            if (!string.IsNullOrWhiteSpace(bbcode))
            {
                Inline inline;
                try
                {
                    var parser = new BbCodeParser(bbcode, this)
                    {
                        Commands = LinkNavigator.Commands
                    };
                    inline = parser.Parse();
                }
                catch (Exception)
                {
                    inline = new Run {
                        Text = bbcode
                    };
                }
                Inlines.Add(inline);
            }
            dirty = false;
        }
コード例 #8
0
        private void CreateRuns()
        {
            if (_state == State.Idle)
            {
                _state = State.CreatingRuns;

                string text = Text;

                Inlines.Clear();

                int segmentLength = SegmentLength;

                for (int i = 0; i < text.Length; i += segmentLength)
                {
                    string segment = i + segmentLength >= text.Length
                        ? text.Substring(i)
                        : text.Substring(i, segmentLength);
                    Inlines.Add(segment);
                }

                _state = State.Idle;

                if (IsInitialized)
                {
                    ApplyAnimations();
                }
            }
        }
コード例 #9
0
 private void SetStatus(StatusMessage statusMessage)
 {
     Inlines.Add(new Run(statusMessage.Message)
     {
         BaselineAlignment = BaselineAlignment.Center, Foreground = Brushes.Green
     });
 }
コード例 #10
0
 private void SetSubscriber(Subscriber subscriber)
 {
     Inlines.Add(new Run(string.Format("{0} just subscribed!", subscriber.User.Name))
     {
         BaselineAlignment = BaselineAlignment.Center, Foreground = Brushes.Red
     });
 }
コード例 #11
0
        private void TextBlockLoaded(object sender, RoutedEventArgs e)
        {
            if (Text.Length == 0)
            {
                return;
            }

            try
            {
                string textUpper  = Text.ToUpper();
                string toFind     = SearchText.ToUpper();
                int    firstIndex = textUpper.IndexOf(toFind);
                string firstStr   = Text.Substring(0, firstIndex);
                string foundStr   = Text.Substring(firstIndex, toFind.Length);
                string endStr     = Text.Substring(firstIndex + toFind.Length, Text.Length - (firstIndex + toFind.Length));

                Inlines.Clear();
                var run = new Run();
                run.Text = firstStr;
                Inlines.Add(run);
                run            = new Run();
                run.FontWeight = FontWeights.Bold;
                run.Foreground = new SolidColorBrush(new Color {
                    R = 187, G = 158, B = 116, A = 255
                });
                run.Text = foundStr;
                Inlines.Add(run);
                run      = new Run();
                run.Text = endStr;
                Inlines.Add(run);
            }
            catch (Exception) { }
        }
コード例 #12
0
ファイル: ZParagraph.cs プロジェクト: ChrisJamesSadler/IL2CPU
        private ZRun AddInline(String Text, CharDisplayInfo DisplayInfo)
        {
            ZRun temp = CreateInline(Text, DisplayInfo);

            Inlines.Add(temp);
            return(temp);
        }
コード例 #13
0
        internal void Update(ParamStorageTag paramStorageTag)
        {
            var txt = paramStorageTag.Type == 0 ? "ref " : paramStorageTag.Type == 1 ? "out " : "lazy ";

            Inlines.Clear();
            Inlines.Add(new Italic(new Run(txt)));
        }
コード例 #14
0
        public void Format()
        {
            Inlines.Clear();
            string[] lines = _plainText.Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                string s = lines[i];
                if (i < lines.Length - 1)
                {
                    s += "\n";
                }
                FontWeight weight;
                double     size = Application.Current.MainWindow.FontSize;
                if (s.Length >= 2 && s[0] == '#' && Char.ToUpper(s[1]) == 'T')
                {
                    weight = FontWeights.Bold;
                    size  *= 2;
                    s      = s.Substring(2);
                }
                else
                {
                    weight = FontWeights.Normal;
                }

                Run inline = new Run();
                inline.FontWeight = weight;
                inline.FontSize   = size;
                inline.Text       = s.TrimStart();
                Inlines.Add(inline);
            }
        }
コード例 #15
0
        private void BuildRunsFromMergedResults(Item resultItem, IEnumerable <Range <Int32> > mergedResult)
        {
            var currentIndex = 0;

            foreach (var range in mergedResult)
            {
                if (currentIndex < range.Start)
                {
                    // add normal run
                    var normalRun = new Run(resultItem.Name.Substring(currentIndex, (range.Start - currentIndex)));
                    Inlines.Add(normalRun);
                }

                // add highlighted run
                var highlightedRun = new Run(resultItem.Name.Substring(range.Start, (range.End - range.Start)));
                Inlines.Add(highlightedRun);
                runs.Add(highlightedRun);

                currentIndex = range.End;
            }

            if (currentIndex < resultItem.Name.Length)
            {
                // add final normal run if necessary
                var normalRun = new Run(resultItem.Name.Substring(currentIndex));
                Inlines.Add(normalRun);
            }
        }
コード例 #16
0
        private void Update()
        {
            if (!IsLoaded || !dirty)
            {
                return;
            }

            string bbcode = BBCode;

            Inlines.Clear();

            if (!string.IsNullOrWhiteSpace(bbcode))
            {
                Inline inline;
                try
                {
                    BBCodeParser parser = new BBCodeParser(bbcode, this, BBCodeQuoteBackground)
                    {
                        Commands = LinkNavigator.Commands
                    };
                    inline = parser.Parse();
                }
                catch (Exception)
                {
                    // parsing failed, display BBCode value as-is
                    inline = new Run {
                        Text = bbcode
                    };
                }
                Inlines.Add(inline);
            }
            dirty = false;
        }
コード例 #17
0
        protected virtual void CharacterPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            Inlines.Clear();
            if (e.OldValue is CharacterViewModel oldValue)
            {
                oldValue.CharacterLists.CollectionChanged -= CharacterListsChanged;
            }
            if (e.NewValue == null)
            {
                return;
            }
            var character = (CharacterViewModel)e.NewValue;

            Inlines.Add(new InlineUIContainer(new Image {
                Source = GetStatusImage(character.Character.Status), Height = 15, Width = 15, UseLayoutRounding = true, SnapsToDevicePixels = true
            })
            {
                BaselineAlignment = BaselineAlignment.TextBottom
            });
            Inlines.Add(new Run(" "));
            nameRun = new Run(character.Character.Name)
            {
                Foreground = new SolidColorBrush(MvxWpfColor.ToNativeColor(Character.GenderColor))
            };
            ApplyListColors();
            character.CharacterLists.CollectionChanged += CharacterListsChanged;
            Inlines.Add(nameRun);
        }
コード例 #18
0
 private void ResetInlines()
 {
     Inlines.Clear();
     foreach (ISection lCurr in ItemsCollection.Items)
     {
         Inlines.Add(lCurr.GetDisplayElement());
     }
 }
コード例 #19
0
 private void BbCodeChanged(DependencyPropertyChangedEventArgs args)
 {
     Inlines.Clear();
     if (args.NewValue == null)
     {
         return;
     }
     Inlines.Add(BBCode.ToInlines((SyntaxTreeNode)args.NewValue));
 }
コード例 #20
0
 public ColourisedQuickInfoContent(IEnumerable <CppToken> tokens)
 {
     foreach (CppToken tok in tokens)
     {
         var   run    = new Run(tok.Text);
         Color colour = GetTokenTypeColour(tok.Type);
         run.Foreground = new SolidColorBrush(colour);
         Inlines.Add(run);
     }
 }
コード例 #21
0
ファイル: EventGraph.cs プロジェクト: modulexcite/marten
        public Aggregator <T> AggregateStreamsInlineWith <T>() where T : class, new()
        {
            var aggregator = AggregateFor <T>();
            var finder     = new AggregateFinder <T>();
            var projection = new AggregationProjection <T>(finder, aggregator);

            Inlines.Add(projection);

            return(aggregator);
        }
コード例 #22
0
 private void OnRichTextChange(RichText richText)
 {
     if (richText == null)
     {
         return;
     }
     Inlines.Clear();
     Inlines.Add(richText.ToSpan());
     RegisterAccessKey();
 }
コード例 #23
0
 private void _OnBindableInlinesChanged()
 {
     Inlines.Clear();
     if (BindableInlines != null)
     {
         foreach (Inline inline in BindableInlines)
         {
             Inlines.Add(inline);
         }
     }
 }
コード例 #24
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Property == TextProperty)
            {
                Inlines.Clear();
                int codepoint = StringToCodepoint(Text);
                Inlines.Add(new InlineUIContainer(new ColorGlyph(m_font, codepoint)));
            }
        }
コード例 #25
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Property == TextProperty)
            {
                Inlines.Clear();

                var canvas = new EmojiCanvas();
                canvas.Reset(Text, FontSize);
                Inlines.Add(new InlineUIContainer(canvas));
            }
        }
コード例 #26
0
        private void Update()
        {
            this.Inlines.Clear();

            if (TextSource == null)
            {
                return;
            }

            foreach (var inline in CreateTemplateInstance(TextSource).SelectMany(inlineHolder => inlineHolder.Inlines))
            {
                Inlines.Add(inline);
            }
        }
コード例 #27
0
        private (bool, int) DecodeTag(string content, Regex reg, StringBuilder text, Func <Match, Inline> process)
        {
            var match = reg.Match(content);

            if (match.Groups[0].Index == 0)
            {
                if (text.Length > 0)
                {
                    Inlines.Add(new Run(text.ToString())); text.Clear();
                }
                Inlines.Add(process(match));
                return(true, match.Length);
            }
            return(false, 0);
        }
コード例 #28
0
        public NoXmlComments(ReflectedMember entry)
        {
            Resources.MergedDictionaries.Add(DocumentationResources.BaseResources);
            Style = (Style)FindResource("NoComments");

            Inlines.Add(new Run(
                            string.Format("No XML comments file found for declaring assembly '{0}'. ",
                                          System.IO.Path.GetFileName(entry.Assembly.FileName))
                            ));

            Hyperlink info = new Hyperlink(new Run("More information."));

            info.NavigateUri      = new Uri(HelpUri);
            info.RequestNavigate += info_RequestNavigate;
            Inlines.Add(info);
        }
コード例 #29
0
ファイル: WordsTable.cs プロジェクト: panda-eye/reading
        private void InitializeComponent()
        {
            foreach (var block in Splitter.Blocks)
            {
                Brush brush = null;
                switch (CurrentColor)
                {
                case 1:
                {
                    brush = Brushes.Blue;
                    CurrentColor++;
                    break;
                }

                case 2:
                {
                    brush = Brushes.Red;
                    CurrentColor++;
                    break;
                }

                case 3:
                {
                    brush = Brushes.Black;
                    CurrentColor++;
                    break;
                }

                case 4:
                {
                    brush        = Brushes.Green;
                    CurrentColor = 1;
                    break;
                }
                }
                var run = new Run(block.Block)
                {
                    Foreground = brush
                };
                Inlines.Add(run);
                //var dot = new Dot(this, run, brush);
                //Layer.Add(dot);
                //Dots.Add(dot);
            }
        }
コード例 #30
0
    private void UpdateInlines(string text)
    {
        //text = @"{Customer.Panel.field}";
        var runs = new List <Run>();
        var sb   = new StringBuilder();

        foreach (var current in text)
        {
            if (current.Equals('}') || current.Equals('{'))
            {
                if (sb.Length == 0)
                {
                    runs.Add(new Run
                    {
                        Text = current.ToString()
                    });
                }
                else
                {
                    runs.Add(new Run
                    {
                        Text       = sb.ToString(),
                        Foreground = Brushes.Red
                    });
                    runs.Add(new Run
                    {
                        Text = current.ToString()
                    });
                    sb.Clear();
                }
            }
            else
            {
                sb.Append(current);
            }
        }
        if (sb.Length > 0)
        {
            runs.Add(new Run {
                Text = sb.ToString(), Foreground = Brushes.Red
            });
        }
        runs.ForEach(run =>
                     Inlines.Add(run));
    }