Custrom控件完全显示后的C#WPF Fire事件

时间:2017-02-10 21:41:30

标签: c# wpf events

我试图找出在显示控件后如何触发事件。例如。

            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}}

真的,它为我工作,但有更好的方法吗?我不确定为什么它可能有用,也许有人可以详细说明,谢谢。

1 个答案:

答案 0 :(得分:0)

将委托函数作为eventHandler传递给Loaded事件。

<强>代码:

control.Loaded += delegate(object o, RoutedEventArgs e){
    SomeMethod();
}