进度条
<pre><code class="language-csharp">&lt;StackPanel VerticalAlignment=&quot;Center&quot;&gt;
&lt;ProgressBar x:Name=&quot;Bar&quot; Minimum=&quot;0&quot; Margin=&quot;10&quot; Height=&quot;10&quot; Value=&quot;0&quot;&gt;&lt;/ProgressBar&gt;
&lt;TextBlock x:Name=&quot;txtPro&quot; HorizontalAlignment=&quot;Center&quot;&gt;&lt;/TextBlock&gt;
&lt;/StackPanel&gt;
/// &lt;summary&gt;
/// ProcessBars.xaml 的交互逻辑
/// &lt;/summary&gt;
public partial class ProcessBars : Window
{
public ProcessBars()
{
InitializeComponent();
this.Loaded += (o,e) =&gt;
{
int count = 77;
Bar.Maximum = count;
Task.Run(async () =&gt;
{
var rand = new Random();
for (int i = 0; i &lt;= 100; i++)
{
_ = this.Dispatcher.InvokeAsync(() =&gt;
{
Bar.Value = i;
txtPro.Text = (i / Convert.ToDouble(count/1.0)).ToString(&quot;p&quot;);
});
await Task.Delay(rand.Next(50,200));
}
});
};
}
}</code></pre>