开发者

C# WPF which method is called when I call a window's show()?

I have window A and window B. In window A I call B.show(). I want to know in window B which method is called and I want to load data when B is showing up. thank开发者_开发技巧s,


You can always listen to the "Loaded" event:

BWindow.Loaded += new RoutedEventHandler(BWindow_Loaded);        

void BWindow_Loaded(object sender, RoutedEventArgs e)
{
    //Your Code here
}

Then in your AWindow call

BWindow.Show();


You may be surprized, but when you call B.Show(), the method which is called is Show().

About loading additional data after window B is shown, you may subscribe to its Loaded event (see answer of @masenkablast). The better idea would be perhaps to derive from Window class and bind to the needed data in XAML. (You are using WPF, not WinForms, I suppose.)


I think it is better to have a Property which is set before B.Show() is called. This way you can always get the method which invokes the show method based on the property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜