一秒钟后更改边框的背景颜色 [英] Change the background color of border after one second
本文介绍了一秒钟后更改边框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我单击边框的按钮背景是蓝色,一秒钟后应该是红色.它是红色但不是蓝色.为什么?
I click the button background of border is blue,after one second it should be red.It is red but not blue.why?
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Border Width="111" Name="op" Height="111">
<Button Name="opbtn" Click="opbtn_Click" Width="50" Height="23">click</Button>
</Border>
</Window>
private void opbtn_Click(object sender, RoutedEventArgs e)
{
op.BorderBrush = System.Windows.Media.Brushes.Blue;
DateTime obj1 = new DateTime();
DateTime obj2 = DateTime.Now.AddMilliseconds(200);
while (obj2 > obj1)
{
obj1 = DateTime.Now;
}
op.BorderBrush = System.Windows.Media.Brushes.Red;
}
推荐答案
AddMilliseconds应该使用1000作为参数一秒钟. 200毫秒仅是一秒的1/5,UI可能需要很长时间才能赶上您想要的内容,因此您实际上并没有*看到*更改.作为测试,我将AddMilliseconds参数设置为2000,只是让您有机会看到它.
AddMilliseconds should use 1000 as a parameter for one second. 200 milliseconds is just 1/5 of a second, and it probably takes that long for the UI to catch up witgh what you want, so you''re not actually *seeing* the change. As a test, I would make the AddMilliseconds parameter 2000, just to give you a chance to see it.
这篇关于一秒钟后更改边框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文