TextBlock with multiple spacing

前端 未结 2 2086
野性不改
野性不改 2020-12-30 20:01

Given a formatted text block in Windows Phone 7.1 project:


    

        
相关标签:
2条回答
  • 2020-12-30 20:22

    if you write all your Runs in the same line, the empty space will go away. Basically a new line here is one empty space on the UI.

    <TextBlock Foreground="DarkGray" VerticalAlignment="Bottom" Margin="0,0,0,8"><Run Text="total length "/><Run Text="{Binding TotalHours}" FontSize="48"/><Run Text="h "/><Run Text=":" FontSize="48"/><Run Text="{Binding TotalMinutes}" FontSize="48"/><Run Text="m "/></TextBlock>
    

    enter image description here

    0 讨论(0)
  • 2020-12-30 20:35

    To build off Justin XL's answer, the important part is that you can't have whitespace between the run tags, but whitespace in the tags themselves does't matter...

    So you can get creative to place runs on separate lines, but not add spaces to the result:

    <!-- Formatted to prevent adding spaces between runs -->
    <TextBlock Foreground="DarkGray" VerticalAlignment="Bottom" Margin="0,0,0,8"
        ><Run Text="total length "
        /><Run Text="{Binding TotalHours}" FontSize="48"
        /><Run Text="h "
        /><Run Text=":" FontSize="48"
        /><Run Text="{Binding TotalMinutes}" FontSize="48"
        /><Run Text="m "
    /></TextBlock>
    
    0 讨论(0)
提交回复
热议问题