Progress bar with dynamic text & text color update

前端 未结 3 1149
谎友^
谎友^ 2020-11-30 03:26

I\'ve a progressbar whose text changes dynamically. I want to update the appearance of it such that as soon as progress comes over text then text color should update. Someth

3条回答
  •  难免孤独
    2020-11-30 03:50

    Here is one way to do it using a modified version of the ProgressBars default Template. It contains two TextBlocks

    • The first TextBlock is the black one
    • The second TextBlock is the white one. This TextBlock has the Width of the full control and Clip set to the Width of the progress part

    enter image description here

    The text of the ProgressBar is binding to the Tag property. Usable like this.

    
    

    MyProgressBarStyle

    
        
        
        
    
    
        
        
    
    
        
        
    
    
        
        
    
    
        
        
        
        
    
    
        
        
        
    
    
        
        
        
    
    
        
        
    
    
        
        
    
    
        
        
    
    
        
        
    
    
    

    RectConverter

    public class RectConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double width = (double)values[0];
            double height = (double)values[1];
            return new Rect(0, 0, width, height);
        }
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

提交回复
热议问题