WPF设计带数字标签显示的进度条

2021-05-19 17:30

阅读:455

标签:mamicode   sed   alc   roo   translate   str   rmi   idt   val   

先上图

技术图片

1.xaml代码

2.附加属性

public static string GetPercentage(DependencyObject obj)
        {
            return (string)obj.GetValue(PercentageProperty);
        }

        public static void SetPercentage(DependencyObject obj, string value)
        {
            obj.SetValue(PercentageProperty, value);
        }
        //百分比展示
        // Using a DependencyProperty as the backing store for Percentage.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PercentageProperty =
            DependencyProperty.RegisterAttached("Percentage", typeof(string), typeof(AttachProperty), new PropertyMetadata(""));

3.在设计器中使用

"pro" Style="{StaticResource ProgressBarStyle}" ath:AttachProperty.Percentage="{Binding Percentage}" Height="35" Foreground="#ff2791ff" Background="#ffe5e9f0" Width="600" Value="0" Maximum="100">

4.逻辑代码

private void Func(object obj)
        {
            for (int i = 0; i 100; i++)
            {
                this.pro.Dispatcher.Invoke(new Action(()=> {
                    StyleLibrary.Core.AttachProperty.SetPercentage(pro, i.ToString() + "%");
                    pro.Value = i;
                }));
                Thread.Sleep(100);
            }
        }

//调用
ThreadPool.QueueUserWorkItem(Func,null);

5.知识点:附加属性;绑定;样式;

WPF设计带数字标签显示的进度条

标签:mamicode   sed   alc   roo   translate   str   rmi   idt   val   

原文地址:https://www.cnblogs.com/zhuiyishanran/p/11693125.html


评论


亲,登录后才可以留言!