Text on a ProgressBar in WPF

前端 未结 7 1162
日久生厌
日久生厌 2021-02-01 12:09

This may be a no-brainer for the WPF cognoscenti, but I\'d like to know if there\'s a simple way to put text on the WPF ProgressBar. To me, an empty progress bar looks naked. Th

相关标签:
7条回答
  • 2021-02-01 13:09

    ProgressBar with Text and Binding from 2 Properties ( Value/Maximum value ):

    <Grid>
        <ProgressBar Name="pbUsrLvl"
                     Minimum="1" 
                     Maximum="99" 
                     Value="59" 
                     Margin="5"  
                     Height="24"  Foreground="#FF62FF7F"/>
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock.Text>
                <MultiBinding StringFormat="{}UserLvl:{0}/{1}">
                    <Binding Path="Value" ElementName="pbUsrLvl" />
                    <Binding Path="Maximum" ElementName="pbUsrLvl" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </Grid>
    

    Rezult:


    The same but with % of progress :

    <Grid>
        <ProgressBar Name="pbLifePassed"
                     Minimum="0" 
                     Value="59" 
                     Maximum="100"
                     Margin="5" Height="24" Foreground="#FF62FF7F"/>
        <TextBlock Text="{Binding ElementName=pbLifePassed, Path=Value, StringFormat={}{0:0}%}" 
               HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
    

    0 讨论(0)
提交回复
热议问题