Behind the Curtain

Our team (officially Community Program Managers, with the secret identity of STO Ninjas) has quietly expanded over the past few StoNinja50 months, including the additions of two amazing and terrific new voices: Pete Brown and Jon Galloway.

Their names are linked to their blogs, which I highly recommend subscribing to.

 

 

 

Syntax Highlighting (Finally) Done Right

This posting, however, is occasioned by Jon writing a post on how to make Syntax Highlighter work with Community Server… no small trick, but Syntax Highlighter now supports hosting (!).    Jon provides all the links you need (including a link to our fearless leader’s extensive post on the topic) , and great instructions,

The key benefit is that the code has syntax highlighting but still support clean copy and paste; something I’ve wanted (and readers have demanded) for a long time.

Here’s an example:

using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace SilverlightHVP.ViewModel
{
   public class ItemsViewModel : INotifyPropertyChanged
   {
      private State state;
      public List<Item> Items
      {
         get { return state.CurrentItems; }
         
      }


      public Item CurrentItem
      {
         get { return state.CurrentItem; }
         set 
         {
            if ( value != null )
            {
               state.CurrentItem = value;
               NotifyPropertyChanged( "CurrentItem" );
            }
         }
      }

      public ItemsViewModel( State state )
      {
         this.state = state;
         this.state.CurrentSetChanged += 
            new State.CurrentSetChangedHandler(state_CurrentSetChanged);
         UpdateItems();
      }

      void state_CurrentSetChanged( object sender, EventArgs e )
      {
         UpdateItems();
      }

      private void UpdateItems()
      {
         NotifyPropertyChanged( "Items" );
      }


      public event PropertyChangedEventHandler PropertyChanged;
      private void NotifyPropertyChanged(string propName)
      {
         if (PropertyChanged != null )
         {
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
         }
      }
   }
}

syntax If you are looking at this on line, you should see a very nicely formatted layout with syntax highlighting (see image).  In a stream, however, it is straight html.  Even more valuable, notice the four symbols (circled in red); when you click on the code these appear and offer “show source” (the image has an inlay of the source as it is shown when clicking this). The other three are copy to clipboard, print and help.  Very very nice.

Thanks Jon!

(Click on image for full size)

This work is licensed under a Creative Commons license.
Share

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.
This entry was posted in z Silverlight Archives and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.