When I needed something like this for iOS, I've implemented very basic BBCode-alike markup language with only a few tags: "[b]", "[/b]", "[[" and "]]" (in my project I didn't even needed the italic, only bold).
However, .NET doesn't have an analog of NSScanner class that I used to parse the syntax. Instead, it has much better support for parsing XML data. So, on WP7 it's easier to implement a very basic subset of XML, with just <b> and <i> tags supported. See the end of this page for sample code.
Here's how to add formatted text pieces into the WP7 TextBlock.
Update: OK, here's the complete solution for you:
[Flags]
enum eParseState: byte
{
bold = 1,
italic = 2,
}
// Sample input: "<txt>This is <i>some</i> text. <b>This value is <i>bold</i>.</b> This one is not.</txt>"
static void parseRichText( TextBlock tb, string xml )
{
tb.Inlines.Clear();
XmlReader reader = XmlReader.Create( new StringReader( xml ), new XmlReaderSettings() { ConformanceLevel=ConformanceLevel.Fragment } );
eParseState state = 0;
var names = new Dictionary<string, eParseState>()
{
{ "b", eParseState.bold },
{ "i", eParseState.italic },
};
Action<bool> actElement = ( bool isOpening ) =>
{
string name = reader.Name.ToLower();
eParseState flag;
if( !names.TryGetValue( name, out flag ) ) return;
if( isOpening )
state |= flag;
else
state &= ( ~flag );
};
while( reader.Read() )
{
switch( reader.NodeType )
{
case XmlNodeType.Element:
actElement( true );
break;
case XmlNodeType.EndElement:
actElement( false );
break;
case XmlNodeType.Text:
var run = new Run() { Text = reader.Value };
if( 0 != ( state & eParseState.bold ) ) run.FontWeight = FontWeights.Bold;
if( 0 != ( state & eParseState.italic ) ) run.FontStyle = FontStyles.Italic;
tb.Inlines.Add( run );
break;
}
}
}