我需要在C# 6.0 WPF中创建一个圆角矩形按钮。这个按钮应该有一个进度条,而不是一个顺时针填充的框架(从顶部边框的中间开始)。
我尝试了很多方法来做到这一点,甚至做了一个稍微可行的版本使用路径,但没有圆角,这是我需要的。
请告诉我如何使用xaml标记和如何管理进度。
这是一个圆角的常规按钮:
<UserControl x:Class="Example.ProgressButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Example"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="button" Width="150" Height="60" Content="Click me" Background="LightGray" BorderBrush="Transparent">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="10" Background="{TemplateBinding Background}" BorderBrush="Green" BorderThickness="2">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Grid>
</UserControl>
字符串
最初,框架不应可见(按钮的大小不应随框架的变化而变化);单击时,进度条从上边框的中间开始顺时针填充。填充100%后,按钮应如图所示:x1c 0d1x
此外,进度条的填充即使在圆角上也应该平滑。
我完全不知道该怎么做。请帮帮我。
**更新:**我可能没有很好地解释我的问题,我会尝试澄清。我需要将边框本身作为进度条(作为元素或动画,这并不重要),它应该填充指定的时间,大约如图:load_button
2条答案
按热度按时间qcbq4gxm1#
您可以创建一个派生的
Border
控件,在其边框顶部绘制一个描边的几何体。描边的长度可以由用于绘制边框几何体的Pen
的虚线数组控制。该控件声明了两个附加属性
ProgressBrush
和ProgressValue
,它们是0到1范围内的双精度值。下面的示例仅使用
BorderThickness
的Left
组件和CornerRadius
的TopLeft
组件,因此它不支持不规则的边界厚度或拐角半径。字符串
XAML中的一个示例用法:
型
niwlg2el2#
这是几个问题的组合,包括:
我很快地把一些东西打包在一起,让你开始。还有工作要做;)
x1c 0d1x的数据
Xaml:
字符串
Cs:
型
如果你想
的
然后做以下更改:
Stroke="Green"
Background="{TemplateBinding Background}"
和BorderBrush="Transparent"
这样,按钮椭圆化动画路径的内部部分,只留下外部线可见,因为它的变化。