首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

show()下的delegate就管用 为什么showdialog()下的delegate就失效了呢,该如何解决

2012-03-27 
show()下的delegate就管用 为什么showdialog()下的delegate就失效了呢今天无意中做了个小测试. 如果我写w.

show()下的delegate就管用 为什么showdialog()下的delegate就失效了呢

今天无意中做了个小测试. 如果我写w.show();的话 delegate下的内容就可以命中

C# code
            Window1 w = new Window1();            w.Show();            w.Closed += delegate            {                dataGrid1.ItemsSource = IO.TE.Table.ToList();                listBox1.ItemsSource = IO.TE.Table.ToList();            };            

但是如果我写w.showdialog(); delegate可以命中 但是delegate的内容就不能命中了 这是为什么呢?

C# code
            Window1 w = new Window1();            w.ShowDialog();            w.Closed += delegate            {                dataGrid1.ItemsSource = IO.TE.Table.ToList();                listBox1.ItemsSource = IO.TE.Table.ToList();            };        


[解决办法]
在ShowDialog之前绑定事件处理程序
也就是w.Closed += delegate在ShowDialog之前

热点排行