Exemple #1
0
        public static List <XmlToken> Tokenize(string input)
        {
            XmlTokenizerMode mode      = XmlTokenizerMode.OutsideElement;
            XmlTokenizer     tokenizer = new XmlTokenizer();

            return(tokenizer.Tokenize(input, ref mode));
        }
    public static FlowDocument ColorizeXAML( string xamlText, FlowDocument targetDoc )
    {
      XmlTokenizer tokenizer = new XmlTokenizer();
      XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement;

      List<XmlToken> tokens = tokenizer.Tokenize( xamlText, 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 = xamlText.Substring( position, token.Length );
        tokenTexts.Add( tokenText );
        Color color = ColorForToken( token, tokenText );
        colors.Add( color );
        position += token.Length;
      }

      Paragraph p = new Paragraph();

      // Loop through tokens
      for( int i = 0; i < tokenTexts.Count; i++ )
      {
        Run r = new Run( tokenTexts[ i ] );
        r.Foreground = new SolidColorBrush( colors[ i ] );
        p.Inlines.Add( r );
      }

      targetDoc.Blocks.Add( p );

      return targetDoc;
    }
Exemple #3
0
 public static List<XmlToken> Tokenize( string input )
 {
   XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement;
   XmlTokenizer tokenizer = new XmlTokenizer();
   return tokenizer.Tokenize( input, ref mode );
 }