public static List <XmlToken> Tokenize(string input) { XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement; XmlTokenizer tokenizer = new XmlTokenizer(); return(tokenizer.Tokenize(input, ref mode)); }
public void Highlight(string line) { _paragraph.Inlines.Clear(); XmlTokenizer tokenizer = new XmlTokenizer(); XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement; List <XmlToken> tokens = tokenizer.Tokenize(Xaml, ref mode); List <string> tokenTexts = new List <string>(tokens.Count); List <Color> colors = new List <Color>(tokens.Count); int position = 0; foreach (XmlToken token in tokens) { string tokenText = Xaml.Substring(position, token.Length); tokenTexts.Add(tokenText); Color color = ColorForToken(token, tokenText); colors.Add(color); position += token.Length; } for (int i = 0; i < tokens.Count; i++) { Run run = new Run(); run.Foreground = new SolidColorBrush(colors[i]); run.Text = tokenTexts[i]; _paragraph.Inlines.Add(run); } }
public static List<XmlToken> Tokenize(string input) { XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement; XmlTokenizer tokenizer = new XmlTokenizer(); return tokenizer.Tokenize(input, ref mode); }
protected void OnTextChanged() { _paragraph.Inlines.Clear(); var tokenizer = new XmlTokenizer(); XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement; List<XmlToken> tokens = tokenizer.Tokenize(Xaml, ref mode); var tokenTexts = new List<string>(tokens.Count); var colors = new List<Color>(tokens.Count); int position = 0; foreach (XmlToken token in tokens) { string tokenText = Xaml.Substring(position, token.Length); tokenTexts.Add(tokenText); Color color = ColorForToken(token, tokenText); colors.Add(color); position += token.Length; } for (int i = 0; i < tokens.Count; i++) { Run run = new Run(); run.Foreground = new SolidColorBrush(colors[i]); run.Text = tokenTexts[i]; _paragraph.Inlines.Add(run); } }