当存在按键按下事件回调时,分派器计时器不会计时。 在实际程序中,输入被传递到另一个线程进行处理和 返回到UI线程进行显示。
每个用户输入我都需要一个持久弹出窗口
namespace TextBoxTest
{
public partial class MainWindow : Window
{
static public StreamWriter tw = new StreamWriter("T_file.txt");
static private bool flg;
static private string ss;
public MainWindow()
{
InitializeComponent();
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += TimerTick;
timer.Interval = TimeSpan.FromSeconds(1);
timer.Start();
flg = false;
tw.WriteLine("window initial");
tw.Flush();
}
private void keyDownEvent (object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
tw.WriteLine("keydown -- return");
tw.Flush();
var textbox = sender as TextBox;
tw.WriteLine(textbox.Text);
ss = textbox.Text;
tw.Flush();
textbox.Text = "";
flg = true;
}
}
public void TimerTick(object sender, EventArgs e)
{
tw.WriteLine("timer tick entry");
tw.Flush();
if (flg == false) return;
Window wa = new Window();
wa.Height = 100;
wa.Width = 200;
wa.Title = "CCC";
wa.Content = ss;
wa.Show();
flg = false;
tw.WriteLine("timer tick exit");
tw.Flush();
}
}
}
Timer tick
未输入。