如何在“n”次迭代后将进度条重置为零?WPF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23249990/
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
How to reset progress bar to zero after 'n' number of iterations? WPF
提问by Brian J
I added a progress bar to a WPF application that counts how many times a gesture is performed. But I want the progress bar to reset to zero after 20 iterations.
我向 WPF 应用程序添加了一个进度条,用于计算一个手势执行的次数。但我希望进度条在 20 次迭代后重置为零。
I tried to achieve this in the below code but when the bar gets to 20 it keeps counting and progress shows full. My question is how do I fix my loop to allow for this?
我试图在下面的代码中实现这一点,但是当条形达到 20 时,它会继续计数并且进度显示已满。我的问题是如何修复我的循环以允许这样做?
void matcher_GestureMatch(Gesture gesture)
{
scoreProgBar.Maximum = 20;
lblGestureMatch.Content = gesture.Name;
if(scoreCntr == 20)
{
scoreCntr.Equals(0);
}
scoreCntr++;
scoreProgBar.Value = scoreCntr;
lblScoreCntr.Content = scoreCntr;
}
采纳答案by DGibbs
This line:
这一行:
scoreCntr.Equals(0);
Doesn't do what you probably think it does. It will compare the current object instance (scoreCntr) to the other object passed as the parameter (0).
不会做你可能认为它会做的事情。它将当前对象实例 (scoreCntr) 与作为参数 (0) 传递的另一个对象进行比较。
You probably want something like this:
你可能想要这样的东西:
if(scoreCntr == 20)
{
scoreCntr = 0;
}
回答by Muhammad Umar
May be something like this,
可能是这样的
void matcher_GestureMatch(Gesture gesture)
{
scoreProgBar.Maximum = 20;
lblGestureMatch.Content = gesture.Name;
if(scoreCntr == 20)
{
scoreCntr = 0;
}
else
{
scoreCntr++;
}
scoreProgBar.Value = scoreCntr;
lblScoreCntr.Content = scoreCntr;
}
回答by it's Manon
**U can try this :
**你可以试试这个:
}**` if (progressBar1.Value == 100)
{
progressBar1.Value = 0;
}**`
回答by Weyland Yutani
scoreCntr = 0;
not
不是
scoreCntr.Equals(0);

