locked
Is there any way to vertically align text with an InlineUIContainer?

    Question

  • I have a c++ app pulling custom markup from a database backend, thus dynamic data, and I am generating "fractions" from this data. The way I am implementing the fractions is similar to(I am actually creating the elements in code):

    <InlineUIContainer>
        <StackPanel>
            <TextBlock x:Name="numeratorTB" Text="(50)x100" />
            <Line X2="{Binding ElementName=numeratorTB, Path=ActualWidth}" Stroke="{StaticResource ApplicationForegroundThemeBrush}"/>
            <TextBlock Text="-57 + 24"/>
        </StackPanel>
    </InlineUIContainer>

    The way I want this to appear in the app is with adjacent text in the paragraph vertically aligned to the center of the StackPanel/"fraction".

    I achieved this by reducing the fontsize in the fraction (14.0 for the fraction versus 18.0 for the surrounding text) and putting a margin of

    fractionSP->Margin = Thickness(0, 14, 0, -14);

    This works somewhat well, but if the RichTextBlock is within a Border, within a ListView element, I get an awkward visual where the text pokes out of the border and out of the ListView hoverOver shading.  Further, if there is substantial surrounding text there will be a mismatch between the space between the previous line and this line, and further this line and the following line.

    Is there a better way to do this?

    Sunday, August 17, 2014 2:18 PM

Answers

  • Hi Sharif,

    Seems there is no good way to do it.

    But you may want to try something like TranslateTransform:

            <RichTextBlock>
                <Paragraph>
                    <Run Text="Hello World"/>
                    <InlineUIContainer >
                        <Button Content="Click Me">
                            <Button.RenderTransform>
                                <TranslateTransform Y="40" X="-60"/>
                            </Button.RenderTransform>
                        </Button>
                    </InlineUIContainer>
                </Paragraph>
            </RichTextBlock>

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, August 19, 2014 2:00 AM
    Moderator