zoukankan      html  css  js  c++  java
  • WPF ProgressBar 样式

    希望写个ProgressBar的样式,在progress value不同的时候显示不同的颜色的progress bar

    1.写转换器

    public class ProgressBarValueConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                double v = (double)value;
    
                string imageUri = "../Images/progress bar_1.png";
    
                if (v > 80)
                {
                    imageUri = "../Images/progress bar_3.png";
                }
                else if (v > 50)
                {
                    imageUri = "../Images/progress bar_2.png";
                }
    
                BitmapImage img = new BitmapImage(new Uri(imageUri, UriKind.Relative));
    
                return img;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    2.创建样式

        <c:ProgressBarValueConverter x:Key="pbConverter"/>
        <Style x:Key="ProgressBarStyle" TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Image Name="PART_Track" Source="../Images/progress bar.png" HorizontalAlignment="Left" Stretch="Fill"/>
                            <Image Name="PART_Indicator" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Converter={StaticResource pbConverter}}"
                                       HorizontalAlignment="Left" Stretch="Fill"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    3.设置progress bar的style

    progress bar.png: 

    progress bar_1.png: 

    progress bar_2.png:

    progress bar_3.png:

    ------------------------------------------------------------------

    如果仅仅是希望创建一个扁平化的progress bar,那么连转换器都可以不用写

    <Style x:Key="FlatProgressBar" TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Image Name="PART_Track" Source="../Images/Flat Progress Bar.png" HorizontalAlignment="Left" Stretch="Fill"/>
                            <Image Name="PART_Indicator" Source="../Images/Flat Progress Bar_1.png" HorizontalAlignment="Left" Stretch="Fill"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    Flat Progress Bar.png:

    Flat Progress Bar_1.png:

    
    
  • 相关阅读:
    Linux下VFP NEON浮点编译
    硬浮点 VFP
    程序员如何避免猝死?
    程序员谨防加班猝死之十大建议
    linux系统调用和库函数调用的区别
    彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义
    LoadRunner监控mysql利器-SiteScope(转)
    linux mysql 数据库开启外部访问设置指南
    Java Web自定义MVC框架详解 (转)
    Jenkins+Ant+Jmeter搭建持续集成的接口测试平台(转)
  • 原文地址:https://www.cnblogs.com/AlvinLiang/p/5513096.html
Copyright © 2011-2022 走看看