views:

51

answers:

1

I'm using the new RichTextBox control in SL4Beta and want to create styles for paragraphs and runs (blocks and inlines). I noticed that I can create a style for a <Block/>, like so:

<Style x:Key="lvl2Paragraph" TargetType="Block">
    <Setter Property="FontFamily" Value="Times New Roman"/>
    <Setter Property="FontStyle" Value="Italic"/>
    <Setter Property="FontSize" Value="22"/>
</Style>

But I can't set that to a <Paragraph/> as The member "Style" member is not recognized or not accessible. Like this:

<RichTextBox TextWrapping="Wrap">
    <Paragraph Style="{StaticResource lvl2Paragraph}">
        Can't set a style for a paragraph.
    </Paragraph>
</RichTextBox>

Is there anyway to make "Style" exposed for the RichTextBox? I'm open to all ideas.

+1  A: 

Style is a property and mechanism supported by elements that inherit from FrameworkElement. However the contents of RichTextBox are lightweight, they do not have FrameworkElement or even UIElement in their class ancestory.

The only way I can think of to mitigate this is to create an Attached property to take the place of the missing Style property. However you would have implement in that attached property all the setting of the other properties. It would sensitive to document order if inline Xaml also sets the same properties.

AnthonyWJones
Thanks Anthony for the insight and too bad it can't be easier than this. It doesn't seem to make any sense to be able to create a style for `<Block/>` but not be able to use it. Maybe the RC or RTW version of SL4 will offer it though.
Otaku
@Otaku: It may seem a bit strange that you are allowed to create one that doesn't refer to a `FrameworkElement` but I think that approach is right. Its reasonable to keep a door open if its not dangerous to do so. For example my suggestion above would be a non-starter if such a restriction were in place.
AnthonyWJones