问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

wpf 如何将条纹对进度条进行填充,而不是拉伸

发布网友 发布时间:2022-04-22 12:45

我来回答

1个回答

热心网友 时间:2023-10-14 06:56

这种情况应该是填充的进度条的是有损图片资源 ,在填充后放大出现拉伸。

建议使用WPF上面的画刷 SolidColorBrush或Color进行对进度条填充,这些资源在WPF框架都是矢量的。无论你放大多少倍都不会失真。

下面是我自己用的一个ProgressBar模板,可以使用下面的模板或自己定义:

        <LinearGradientBrush x:Key="WindowBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF4785B0" Offset="0"/>
            <GradientStop Color="#FF63AADA" Offset="1"/>
        </LinearGradientBrush>
        <Color x:Key="PrimaryColor">#FF63AADA</Color>
        <Color x:Key="SecondaryColor">#FFA0FCFF</Color>
        <SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource PrimaryColor}" />
        <SolidColorBrush x:Key="SecondaryBrush" Color="{DynamicResource SecondaryColor}" />
        <SolidColorBrush x:Key="TextBrush" Color="#FF152937" />

        <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
            <Setter Property="Foreground" Value="{StaticResource TextBrush}" />
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFB4B4B4" />
                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Maximum" Value="100" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="BorderBrush" Value="{StaticResource PrimaryBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid x:Name="Root" SnapsToDevicePixels="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.5*" />
                                <RowDefinition Height="0.5*" />
                            </Grid.RowDefinitions>
                            <Border CornerRadius="4" x:Name="White" BorderBrush="#FFFFFFFF" BorderThickness="1" Grid.RowSpan="2">
                                <Border.Background>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.35" ScaleY="1.35" />
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFFFFFF" Offset="0" />
                                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                                    </RadialGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border x:Name="PART_Track" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4" Grid.RowSpan="2" Opacity="0.65" />
                            <Grid x:Name="ProgressBarRootGrid" Grid.RowSpan="2">
                                <Rectangle x:Name="ProgressBarRootGradient" Canvas.ZIndex="1" Stroke="#FFFFFFFF" StrokeThickness="1" RadiusX="4" RadiusY="4" Opacity="0.65">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.7,1.263" StartPoint="0.699999988079071,0">
                                            <GradientStop Color="{StaticResource PrimaryColor}" Offset="0.312" />
                                            <GradientStop Color="{StaticResource SecondaryColor}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Grid x:Name="IndeterminateRoot" Visibility="Collapsed">
                                    <Rectangle Margin="{TemplateBinding BorderThickness}" x:Name="IndeterminateSolidFill" Opacity="1" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding Foreground}" Stroke="#FF448DCA" StrokeThickness="0" RadiusX="4" RadiusY="4" />
                                    <Rectangle Margin="{TemplateBinding BorderThickness}" x:Name="IndeterminateGradientFill" Opacity="0.7" StrokeThickness="1" RadiusX="4" RadiusY="4">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush MappingMode="Absolute" SpreadMethod="Repeat" EndPoint="0,1" StartPoint="20,1">
                                                <LinearGradientBrush.Transform>
                                                    <TransformGroup>
                                                        <TranslateTransform X="0" />
                                                        <SkewTransform AngleX="-30" />
                                                    </TransformGroup>
                                                </LinearGradientBrush.Transform>
                                                <GradientStop Color="#FFFFFFFF" Offset="0" />
                                                <GradientStop Color="#00FFFFFF" Offset=".25" />
                                                <GradientStop Color="#FFFFFFFF" Offset="0.85" />
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                </Grid>
                                <Grid Margin="1" x:Name="DeterminateRoot">
                                    <Rectangle HorizontalAlignment="Left" Margin="2" x:Name="PART_Indicator" StrokeThickness="0.5" RadiusX="4" RadiusY="4" Fill="{StaticResource PrimaryBrush}" />
                                </Grid>
                            </Grid>
                            <Border BorderBrush="#ccFFFFFF" BorderThickness="1" CornerRadius="3.5" x:Name="InnerBorder" Margin="2" Grid.RowSpan="2" />
                            <Border CornerRadius="3.5" x:Name="Shadow" Margin="2" Opacity="0.2" Grid.RowSpan="2">
                                <Border.OpacityMask>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <TranslateTransform X="0" Y="-0.5" />
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#00FFFFFF" Offset="0.3" />
                                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                                    </RadialGradientBrush>
                                </Border.OpacityMask>
                                <Border.Background>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.75" ScaleY="2.25" />
                                                <TranslateTransform Y="0.65" />
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#00000000" Offset="0.55" />
                                        <GradientStop Color="#4C000000" Offset="1" />
                                    </RadialGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border Margin="1" CornerRadius="4,4,4,10" x:Name="Highlight" Opacity="0.8" RenderTransformOrigin="0.5,1">
                                <Border.Background>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.25" ScaleY="2" />
                                                <TranslateTransform Y="-0.6" />
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#BFFFFFFF" Offset="0" />
                                        <GradientStop Color="#4CFFFFFF" Offset="1" />
                                    </RadialGradientBrush>
                                </Border.Background>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsIndeterminate" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard RepeatBehavior="Forever">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateGradientFill" Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.Transform).(TransformGroup.Children)[0].X">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="0" />
                                                <SplineDoubleKeyFrame KeyTime="00:00:.5" Value="20" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Setter Property="Visibility" Value="Visible" TargetName="IndeterminateRoot" />
                                <Setter Property="Visibility" Value="Collapsed" TargetName="DeterminateRoot" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

亲测有效,运行效果:

这样,无论将ProgressBar怎样放大,进度条不会产生失真或拉伸的现象。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
黎明杀机食人魔技能效果介绍介绍_黎明杀机食人魔技能效果介绍是什么_百 ... 黎明杀机怎么传授技能 2周岁宝宝感冒吃什么药 孩子可以吃小儿氨酚黄那敏颗粒能吃吗 回记绿豆糕如何制作口感更好? 回记绿豆糕的烹饪方法是怎样的? 回记绿豆糕的制作方法是怎样的? 河北回记绿豆糕的做法有哪些? 怎样做出地道且美味的回记绿豆糕? 回记绿豆糕有哪些复杂的制作工艺? wpf 进度条 WPF 进度条如何与视频同步 请问大病医疗补充保险是啥意思 城乡居民补充养老保险是指什么 城乡居民养老补充保险必须交吗 补充养老金保险是什么意思 城镇居民基本医疗保险补充保险 城乡居民保险有基保加补保,其中补保是什么意思? 404 Not Found 农村补充养老保险是什么? 2022年城乡居民养老保险和补充保险是一回事吗 城乡医保补充50元保险 补充养老保险是什么意思 山西省城乡居民补充养老保险是什么意思 农村补充养老保险是什么意思 向平安陆金所借款靠谱吗?怎么好多人都说是大坑啊!? 陆金所理财可靠吗 陆金所靠谱吗? 在陆金所理财靠谱不靠谱呀? 陆金所和其他的平台相比,优势在哪儿? WPF 安装文件显示进度条 用WPF如何制作QQ播放器那个音乐进度条(如下图:) WPF进度条更新问题 我在wpf写了一个进度条窗口,然后再页面会触发这个进度条窗口,但是为什么进度条不实时更新,直接到100% WPF 带进度条的窗体根据主窗体的值实时更新? C#内wpf 的一个usercontrol(圆环进度条)只有 showdialog后才会显示 wpf 进度条不能正常的显示?怎么办呢? wpf 做进度条时为什么进度条不同步显示,而是程序运行完之后才一下显示 在wpf中,怎样用progressbar wpf web应用中,如何使用progressbar? wpf使用进程弹出进度条窗体怎么写?求源代码 求WPF加载窗体时弹出另一个窗体并显示进度条的源码,万分感谢! 两个进度条,加上百分比显示 C#怎么利用panel和Picturebox做进度条?还要改变播放过的背景,有没有具体一点的。 wpf 的RadBusyIndicator是干什么用的? 加在GridView的外面? C# WPF 如何画一个温度计 c#wpf ui线程只有一个吗 vivo手机像素怎么看? vivo手机如何查看相片焦距? 怎么样看vivo手机是不是正品或者新机