C# 在文本框中查看输入文本一秒钟,然后更改为passwordchar

C# 在文本框中查看输入文本一秒钟,然后更改为passwordchar,c#,wpf,textbox,C#,Wpf,Textbox,和这个一样,但最后的答案是我想要的。。我需要c#wpf。。。我试了最后一个答案,但似乎找不到时间间隔。。有时可以看到按下的键,有时看不到。。按键时如何获得相同的间隔 private void TextBox_KeyDown(object sender, KeyEventArgs e) { dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new Ti

和这个一样,但最后的答案是我想要的。。我需要c#wpf。。。我试了最后一个答案,但似乎找不到时间间隔。。有时可以看到按下的键,有时看不到。。按键时如何获得相同的间隔

private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
    dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
    dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
    dispatcherTimer.Start();
}
我试过了

dispatcherTimer.Interval = TimeSpan.FromSeconds(5);
但还是一样

编辑

private void dispatcherTimer_Tick(object sender, EventArgs e)
{   
    string str = "";
    for(int i = 0; i < txtPass.Text.Length; i++)
        str += char.ConvertFromUtf32(8226);

    txtPass.Text = str;
    txtPass.Select(txtPass.Text.Length, 0);
}
private void dispatchermer_Tick(对象发送方,事件参数e)
{   
字符串str=“”;
for(int i=0;i
您不需要每次都订阅新的事件处理程序。只需在构造函数中执行一次

dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
Keydown
事件中,只需重置
计时器
(很遗憾,我们没有任何
重置
方法)

当计时器滴答作响时,只需停止计时器并开始工作

void dispatcherTimer_Tick(object sender, EventArgs e)
{
    dispatcherTimer.Stop();
    //your code
}

链接到另一个问题并不妨碍你提问我们需要查看Dispatchermer的实现。我已经编辑了你的标题。请参见“”,其中共识是“不,他们不应该”。我建议您使用
txtPass.Text=newstring(char.ConvertFromUtf32(8226),txtPass.Text.Length),,regardless@Yorye内森,那是什么意思?我怎样才能让密码可见?或者把它改成文本?
void dispatcherTimer_Tick(object sender, EventArgs e)
{
    dispatcherTimer.Stop();
    //your code
}