【问题标题】:Get ClassName of a Window from Window Reference从窗口引用中获取窗口的 ClassName
【发布时间】:2016-12-16 02:12:10
【问题描述】:

我有一个 Window 部分类(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 的实际类名?

【问题讨论】:

  • 更大的问题是为什么你需要传递一个类名。也许您以错误的方式处理您的实际问题。

标签: wpf window classname


【解决方案1】:

只需window.GetType().Name?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多