【问题标题】:Create ProgressBar with Text label near ProgressBar current value在 ProgressBar 当前值附近创建带有文本标签的 ProgressBar
【发布时间】:2015-09-24 19:20:03
【问题描述】:

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

或者:

我怎样才能创建这个?

【问题讨论】:

    标签: wpf progress-bar


    【解决方案1】:

    您可以定义进度条的 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;
    }
    

    注意:如果您需要根据屏幕截图的弹出外观和感觉,则必须修改标签的模板。

    【讨论】:

    • 我正在通过计时器更改进度条,但看不到弹出窗口
    • 您希望在计时器启动后弹出窗口保持打开状态吗?如果是,注释掉 pop.IsOpen = false。
    猜你喜欢
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多