1. kenosando#AC's Avatar
    My app parses XML data and displays it nicely with DataTemplate and embedded TextBlock. I have found ways to format the TextBlock with <Run> tags, but it doesn't appear to possible to add those at run-time. Here is my code:
    <ListBox HorizontalAlignment="Left" Margin="-12,-40,0,0" Name="verses" Width="480" Height="620" SelectionChanged="enableSharing">
    <TextBlock Name="verseBlock" Text="{Binding}" TextWrapping="Wrap" Width="15" HorizontalAlignment="Stretch"
    DataContext="{Binding}" Tag="{Binding}"/>

    The text for the verses are displayed like this:
    1 In the beginning ...

    I create a List<string> in my code that builds each chapter into this format and displays it.
    Essentially, I want just the verse number in bold, and the rest of the text in normal weight. I have seen examples that were non-specific to WP7, using WPF, but I am not sure if importing those libraries will work correctly on a WP device.

    Any suggestions?
    05-18-2012 03:51 PM
  2. rbrunner's Avatar
    WP7 is Silverlight, not WPF. So if you see an article about Silverlight, chances are good it applies to WP7 as well.

    This one does and probably will help you:
    Working with the Silverlight Rich Text Box control
    05-18-2012 04:07 PM
  3. dotnetnelson's Avatar
    Let me save you some trouble: There's no easy way to do this. In WPF it was possible because there was such a thing as a FrameworkContentElement which you could do some black magic on, but its not the case here.

    I solved this a while ago, but never really liked the solution. Basically (and I'm going from memory here) I created an attached property on a "Span" element of type INotifyCollectionChanged. I used the property metadata of the Attached Prop to be notified when the source changed (Think ItemsSource).

    From there, I wired up the CollectionChanged event on the new value and manually added Runs to the Span when elements were added to the collection.

    Like I said, very hideously ugly but it works. The implementation details are hidden from the UI through an attached property, so at least you don't pollute your View code behind.

    I'll see if I can find some old code to provide.
    06-12-2012 09:31 PM