ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

WPF 进度条实现

2020-04-03 09:06:25  阅读:682  来源: 互联网

标签:进度条 实现 object value culture Globalization WPF Type public


1、样式

<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Maximum" Value="100" />
<Setter Property="Height" Value="70" />
<Setter Property="Value" Value="20" />
<Setter Property="Foreground" Value="#40a2c2"/>
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid x:Name="Root">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="35" ></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Canvas Grid.Row="0" Height="38">
<Canvas x:Name="Tooltip" Canvas.Left="{Binding ActualWidth, ElementName=PART_Indicator,Converter={StaticResource progressBarValueLocationConverter}}">
<Image x:Name="Shape_5" Height="30" Canvas.Left="4" Canvas.Top="2" Width="60">
<Image.Effect>
<DropShadowEffect BlurRadius="3" Color="Black" Direction="-90" Opacity="0.43" ShadowDepth="2"/>
</Image.Effect>
</Image>
<TextBlock Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type ProgressBar}},Converter={StaticResource progressBarValueTextFormatConverter}}" Foreground="#FF0000" FontWeight="Bold" FontSize="30" FontFamily="Helvetica75-Bold" IsHyphenationEnabled="True" LineStackingStrategy="BlockLineHeight" Canvas.Left="13" LineHeight="13" TextAlignment="Left" TextWrapping="Wrap" Canvas.Top="9.56">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="0" Color="Black" Direction="-270" Opacity="1" ShadowDepth="1"/>
</TextBlock.Effect>
</TextBlock>
</Canvas>
</Canvas>
</Grid>

<Path Grid.Row="1" x:Name="PART_Track" Data="F1M8,1C8,1 335,1 335,1 338.866,1 342,4.134 342,8 342,11.866 338.866,15 335,15 335,15 8,15 8,15 4.134,15 1,11.866 1,8 1,4.134 4.134,1 8,1z" Canvas.Left="0" Canvas.Top="0">
<Path.Effect>
<DropShadowEffect BlurRadius="0" Color="White" Direction="-90" Opacity="0.26" ShadowDepth="1"/>
</Path.Effect>
<Path.Fill>
<SolidColorBrush Color="Black" Opacity="0.23137254901960785"/>
</Path.Fill>
</Path>
<Border Grid.Row="1" x:Name="PART_Indicator" BorderBrush="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="3,2,0,0" Height="12" MaxWidth="338" Background="{TemplateBinding Foreground}" CornerRadius="7.5,7.5,7.5,7.5" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"></Border>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

2、界面

<ProgressBar Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Value="{Binding CurrentProgress, Mode=OneWay}"
Visibility="{Binding ProgressVisibility, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>

3、转换器

public class ProgressBarValueLocationConverter : IValueConverter
{

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((double)value - 25);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return 0;
}
}


public class ProgressBarValueTextFormatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.ToString() + "%";
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

标签:进度条,实现,object,value,culture,Globalization,WPF,Type,public
来源: https://www.cnblogs.com/huzige/p/12624393.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有