从 Window 参考中获取 Window 的类名
Get ClassName of a Window from Window Reference
我有一个 Window 部分 class (WPF Window) 比如:
public partial class MyWindow : Window
{
// this is just a WPF window
// I have in XAML Closing event like Closing="Window_Closing"
// and here is the event definition
public void Window_Closing(object sender, CancelEventArgs e)
{
SaveWindowState(this); // just passes reference to itself
}
}
在另一个程序集中,我有这样的逻辑接收上面传入的引用
public static void SaveWindowState(Window window)
{
// Since I can call this from many windows, I need a way to get
// the class name of my window in here. Basically, for MyWindow
// above, I need to get "MyWindow" and for other windows, I need
// to get thier class name from the passed in "window" parameter.
}
如何获取传入 Window 的实际 class 名称?
只是 window.GetType().Name
?
我有一个 Window 部分 class (WPF Window) 比如:
public partial class MyWindow : Window
{
// this is just a WPF window
// I have in XAML Closing event like Closing="Window_Closing"
// and here is the event definition
public void Window_Closing(object sender, CancelEventArgs e)
{
SaveWindowState(this); // just passes reference to itself
}
}
在另一个程序集中,我有这样的逻辑接收上面传入的引用
public static void SaveWindowState(Window window)
{
// Since I can call this from many windows, I need a way to get
// the class name of my window in here. Basically, for MyWindow
// above, I need to get "MyWindow" and for other windows, I need
// to get thier class name from the passed in "window" parameter.
}
如何获取传入 Window 的实际 class 名称?
只是 window.GetType().Name
?