Search code examples
wpfreflectionassembliesdependencyobject

Is it possible to find out the assembly and file containing a DependencyObject?


I am currently working on a little localization framework for WPF (don't even think about pointing me to locBAML...) and wondered if it was possible to find out the containing assembly of a specified DependencyObject.

For example: I have a normal window definition in XAML in the file Window1.xaml. The window contains a StackPanel and inside it a TextBlock resides.

Is it possible to find out which assembly contains the Window1.xaml file when only having a reference to the TextBlock?

Is it also possible to find out the file name of the xaml file ("Window1.xaml" in this case)?

Thanks in advance and best regards, 3Fox


Solution

  • I think something like this would work.

    Window window = Window.GetWindow(YourTextBox);
    Assembly assembly = Assembly.GetAssembly(window.GetType());