复制子窗口问题
在我的应用程序中,我有一个“提交”按钮可以执行此操作:
private void Submit_button_Click(object sender, RoutedEventArgs e)
{
string variable = variable_textBox.Text;
if (variable.Length >= 1 && variable.Length <= 6)
{
//get some data from db
}
else
{
ChildWindow msg = new Msg("Some string");
msg.Show();
}
}
这是我的问题:
当我编写一个字符串以使程序转到 else 子句时,将出现一个 childWindow (这是可以的);但如果我再这样做,就会出现 2 个 childWindows。每次单击“提交”按钮,我都会获得 childWindows 的点击次数。
有人能告诉我为什么吗?我在其他地方使用相同的ChildWindow,没有任何问题......
In my application I have a Submit button that does this:
private void Submit_button_Click(object sender, RoutedEventArgs e)
{
string variable = variable_textBox.Text;
if (variable.Length >= 1 && variable.Length <= 6)
{
//get some data from db
}
else
{
ChildWindow msg = new Msg("Some string");
msg.Show();
}
}
Here is my problem:
When I write a string so that the program goes to the else clause, a childWindow will appear (that is OK); but if I do this again, 2 childWindows will appear. For each click on Submit button, I get num of clicks childWindows.
Can someone tell me why? I use the same ChildWindow in other places, and I have no problems...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的意思是:当你在不同的地方使用子窗口时,你没有这个问题?
如果是这样,我只能假设当单击“确定”时,您不仅单击顶部窗口,还单击底部窗口。
您可以添加一个行为,从第一个子窗口中删除 Submit_button_Click 事件。
但为什么要在子窗口中显示消息呢?您可以使用 MessageBox.Show("Some string") 来实现此目的。
Do you mean with then: When you use childwindows on different places you dont have this problem?
If so, I can only assume when clicking OK you dont just click the top window but also the bottom window.
You can add a behaviour that removes the Submit_button_Click event from the first childwindow.
But why show a message in a childwindow? You can use
MessageBox.Show("Some string")
for that.似乎
Submit_button_Click
方法被多次附加到点击事件(每次点击)。通过在其中放置一个断点并查看是否被多次命中来确保情况并非如此。
Seems like
Submit_button_Click
method is being attached multiple times to the click event (for each click).Make sure this is not the case by putting a
breakpoint
in there and see if it is hit multiple times.