Wpf 圆角进度条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32354007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:22:52  来源:igfitidea点击:

Wpf Rounded corners progress bar

c#wpftemplates

提问by Slashy

I'm trying to make a simple progress bar with rounded corners.

我正在尝试制作一个带圆角的简单进度条。

This is my xaml:

这是我的 xaml:

 <Grid>
    <ProgressBar Minimum="0" Maximum="100"  Height="50"  Value="50" Name="pbStatus" BorderBrush="Black" BorderThickness="3" Foreground="#336699"  />
    <TextBlock Text="{Binding ElementName=pbStatus, Path=Value, StringFormat={}{0:0}%}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>

I'm trying to look for the Border-Radiusproperty.... but i just find it. Any help please?

我正在寻找该Border-Radius物业......但我只是找到了它。请问有什么帮助吗?

Thanks.

谢谢。

回答by ELH

From Visual Studio DesignerRight Click on the ProgressBar> Edit Template > Edit a Copy, In the Generated Style add CornerRadiusto the Borderand set the RadiusXand RadiusYin the filling Rectangles :

Visual Studio设计右键点击ProgressBar>编辑模板>编辑副本,在生成的样式添加CornerRadiusBorder并设置RadiusXRadiusY在填充矩形:

<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="30"/>
                        <Rectangle x:Name="PART_Track" />
                        <Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left">
                            <Rectangle x:Name="Indicator" Fill="{TemplateBinding Foreground}" RadiusX="30" RadiusY="30"/>
                            <Rectangle x:Name="Animation" Fill="{TemplateBinding Foreground}" RenderTransformOrigin="0.5,0.5" RadiusX="30" RadiusY="30">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                        </Grid>

回答by WAQ

Put a border inside and set the corner radius property of the border instead. Here is the link describing this progressbar bar style right radius

在里面放置一个边框并设置边框的圆角半径属性。这是描述此进度条样式右半径的链接