在ProgressBar当前值附近创建带有文本标签的ProgressBar

时间:2015-09-24 19:20:03

标签: wpf progress-bar

也许标题有点不清楚所以请看这个图片:

enter image description here

OR:

enter image description here

我该如何创建呢?

1 个答案:

答案 0 :(得分:0)

您可以定义进度条&的ValueChanged事件。将值设置为弹出窗口。请参考以下示例:

//Define a popup in your code, add a Label to it; the below code could be added to the 
//ctor/any other block which would be invoked prior to the ValueChanged event. 
//Please ensure Popup is declared such that it is visble/accessible in any of the 
//functions - in this case, the ValueChanged Event & where you decide to add label & 
//placement values to it.

Popup pop = new Popup();
Label lbl = new Label();
pop.Child = lbl;
pop.Placement = placementMode.Relative;
pop.PlacementTarget = progressBar;//assuming name of ProgressBar is progressbar

private void ProgressBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    pop.IsOpen = true;
    //Set the horizontal offset of Popup in accordance to dimensions of your progress bar
    (pop.Child as Label).Content = progressBar.Value.ToString();
    Thread.Sleep(100);
    pop.IsOpen = false;
}

注意:如果你需要弹出式外观​​&amp;根据您的屏幕截图,您必须修改标签的模板。