Text on a ProgressBar in WPF

前端 未结 7 1164
日久生厌
日久生厌 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 12:50

    If you are needing to have a reusable method for adding text, you can create a new Style/ControlTemplate that has an additional TextBlock to display the text. You can hijack the TextSearch.Text attached property to set the text on a progress bar.

    If it doesn't need to be reusable, simply put the progress bar in a Grid and add a TextBlock to the grid. Since WPF can compose elements together, this will work nicely.

    If you want, you can create a UserControl that exposes the ProgressBar and TextBlock as public properties, so it would be less work than creating a custom ControlTemplate.

提交回复
热议问题