Adding XAML Support to the Unobtrusive Code Highlighter  

Thursday, November 20 2008
I've been working more and more in XAML these days thanks to my new work in Silverlight at Lab49 so I decided it was high time that I added XAML support to the code highlighter that I use. Currently it only supports the Silverlight keyword set, but I plan to support WPF soon. I'm also making additions to the library to support nested rules. For example, if you have a rule nested inside another rule, it should still be highlighted appropriately. I determined this limitation in the current implementation by trying to support Markup Extensions in XAML which only exist inside string rules. You can download the full source here, which includes the 0.5 beta I'm working on. You can check out all the styles I'm supporting on the project page. Here's a sample of the XAML output:

XAML


   <!-- Here are some XAML comments -->
   <Color x:Key="MyBackColor" R="#80" G="#80" B="#C8" A="#FF" />  
   <Style x:Key="ActiveRectangle" TargetType="{x:Type Rectangle}" >  
     <Style.Triggers>  
       <Trigger Property="IsMouseOver" Value="True">  
         <Setter Property="Fill" Value="{ce:RelativeColor BaseColorKey=MyBackColor,Style=Lighten}"/>  
       </Trigger>  
       <Trigger Property="IsMouseOver" Value="False">  
         <Setter Property="Fill" Value="{ce:RelativeColor BaseColorKey=MyBackColor,Style=Normal}"/>  
      </Trigger>  
    </Style.Triggers>  
  </Style>  

Update 7.31.2009: I've updated my version of the unobtrusive code highlighter to support all XAML syntax, both WPF and Silverlight. You can find the code on GitHub

  • Posted by Charlie Robbins