views:

195

answers:

1

I am trying to allow a user to create a table inside of a RichTextBox. I can create a Grid inside of the RichTextBox, but I am having some issues with it.

I start with this XAML in the Grid.

<RichTextBox Name="TB1" AcceptsReturn="True">
    <Paragraph TextAlignment="Center">
        Hi everybody
    </Paragraph>
    <Paragraph>
        <InlineUIContainer>
            <Grid Background="Black">
                <Grid.RowDefinitions>
                    <RowDefinition Height="10" />
                    <RowDefinition Height="10" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="10" />
                </Grid.ColumnDefinitions>
            </Grid>
        </InlineUIContainer>
    </Paragraph>
    <Paragraph>
        How are you today?
    </Paragraph>
</RichTextBox>

Then when I get the XAML out using the Xaml property of the RichTextBox I get this XAML.

<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;

<Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Center">
<Run Text="Hi everybody" />
</Paragraph>

<Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run />
</Paragraph>

<Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run Text="How are you today?" />
</Paragraph>
</Section>

Notice here that the Grid has turned into an empty Run element.

Anyone know why this happens?

A: 

As it turns out the RichTextBox.Xaml Property in Silverlight 4 doesn't include the InlineUIElements. There is a note about it in the documents.

Note that The XAML string returned by the Xaml property will not include any UIElement objects that are present in the content. The InlineUIContainer objects will be converted to empty Run objects.

Brendan Enrick