Search code examples
wpfvisual-studioxamlformattextblock

Using one text block for headers and bodies with bullets and different fonts


I have a ScrollViewer with a TextBlock in it that I want to populate dynamically. I'd like some advice on what the best way to do this is. Here's my XAML with one sample "entry" in the TextBlock.

<ScrollViewer Background="White">
    <ScrollViewer.Resources>
        <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">30</sys:Double>
    </ScrollViewer.Resources>
    <TextBlock FontSize="26"
                   HorizontalAlignment="Left"
                   Margin="25">
            <Run Text="April 14, 2017"
                        FontFamily="VAG Rounded"
                        FontWeight="Bold" /><LineBreak />
            <Run Text="• Updates galore!" /><LineBreak />
            <Run Text="-------------------------------------------------------------------------------------------------------------------" />
    </TextBlock>
</ScrollViewer>

I want just a little space between the VAG Rounded Bold header and the default font body. It doesn't look like a Run allows for margins or padding. Should I just insert an empty line with a very small font size?

I'd appreciate any feedback on the rest of it as well.


Solution

  • If you use a Panel such as a Grid as the Content of the ScrollViewer you could use several TextBlocks with individual margins, e.g.:

    <ScrollViewer Background="White">
            <ScrollViewer.Resources>
                <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">30</sys:Double>
            </ScrollViewer.Resources>-->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock FontSize="26" FontFamily="VAG Rounded" FontWeight="Bold" Text="April 14, 2017" />
            <TextBlock FontSize="26" Margin="25" Grid.Row="1">
                <Run Text="• Updates galore!" />
                <LineBreak />
                <Run Text="-------------------------------------------------------------------------------------------------------------------" />
            </TextBlock>
        </Grid>
    </ScrollViewer>