我试图找出在显示控件后如何触发事件。例如。
int count = 0;
foreach (DataTable table in e.Tables)
{
count++;
control = new LeagueControl(table);
SP1.Children.Add(control);
if (count == e.Tables.Count)
{
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() =>
{
Console.WriteLine("X");
}));
}
}
所以在我添加到SP1的控件后实际显示在我的Window中我想运行方法SomeMethod();
这样做我能得到我需要的东西。
{{1}}
真的,它为我工作,但有更好的方法吗?我不确定为什么它可能有用,也许有人可以详细说明,谢谢。
答案 0 :(得分:0)
将委托函数作为eventHandler传递给Loaded事件。
<强>代码:强>
control.Loaded += delegate(object o, RoutedEventArgs e){
SomeMethod();
}