Son*_*hja 2 .net c# wpf progress-bar
我正在尝试开发一个相应ProgressBar填充到我手动设置的值.例如,我有这个ProgressBar:
<ProgressBar Height="33" HorizontalAlignment="Left" Name="progressBar1" VerticalAlignment="Top" Width="285" />
Run Code Online (Sandbox Code Playgroud)
我有一个按钮,ProgressBar每按一次就会增加10个单位的值,如下所示:
private void button1_Click(object sender, RoutedEventArgs e)
{
progressBar1.Value += 10;
}
Run Code Online (Sandbox Code Playgroud)
我希望每次点击它时都会对该值进行动画处理.我试过这个:
Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
progressBar1.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
Run Code Online (Sandbox Code Playgroud)
但它从0到100的值ProgressBar.如何告诉动画停止特定值,而不是100%?
小智 10
Value如果您执行以下操作,实际上您将动画设置为最终值200:
DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
Run Code Online (Sandbox Code Playgroud)
而是将第一个参数更改为要设置为动画的值.您的事件处理程序应如下所示:
private void button1_Click(object sender, RoutedEventArgs e)
{
Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation doubleanimation = new DoubleAnimation(progressBar1.Value + 10, duration);
progressBar1.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6924 次 |
| 最近记录: |