2016-08-09 2 views
-2

ウインドウ・リファレンス(WPFウィンドウ)などから、ウィンドウのクラス名を取得する:別のアセンブリで私はウィンドウ部分クラスを有する

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. 
} 
ような上記に渡された参照を受信するロジックを有します

渡されたウィンドウの実際のクラス名を取得するにはどうすればよいですか?

+0

もっと大きな質問は、あなたがクラス名を渡す必要がある理由です。たぶんあなたの実際の問題に間違ったやり方で近づいています。 –

答えて

1

単純にwindow.GetType().Name

+0

ありがとうH.B.それは動作します。 – pixel

関連する問題