I’ve a question about localization resources at windows-phone.
Let’s say, I have a string in my Resources file, which should look like as:
This is some text. This value is bold. This one is italic.
And that all stored in a single string field. How could I define such text styles like bold or italic in the Resources itself? I know, I can predefine some custom fonts, like this:
<FontFamily x:Key="CustomBold">...</FontFamily>
and then add is as {StaticResource CustomBold} in page, but that can be a solution if the whole text in string field is bold. And what if I want to make bold a single word in the middle of the phrase?
I want to use native c#-style Resources(i.e. string name -> string value), not writing different implementation.
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: