2

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

starblue
  • 55,348
  • 14
  • 97
  • 151
chrischu
  • 3,047
  • 3
  • 27
  • 44

1 Answers1

2

I think something like this would work.

Window window = Window.GetWindow(YourTextBox);
Assembly assembly = Assembly.GetAssembly(window.GetType());
mdm20
  • 4,475
  • 2
  • 22
  • 24
  • I'm currently at work and so can't check this immediately but don't you think the assembly that I would get out of this would be the assembly containing the Window class (besides other WPF classes) rather then my assembly? – chrischu May 07 '09 at 08:04
  • Since the 'window' is an object inherited from the Window class, GetType() would return that inherited type (e.g. MyWindow). So with this you'll probably get the assembly. – arconaut May 08 '09 at 14:20
  • You're right it works to get the Assembly but I haven't found a way to find out with codefile/class the DO is in. – chrischu May 10 '09 at 16:00
  • It is possible to just the traverse the logical tree of the DependencyObject upwards till you hit the base class (be it a Window, UserControl etc.) this is the class at least. I don't think there is a way to find out which codefile it was defined in. – chrischu May 10 '09 at 16:41
  • You can recursively go up each controls Parent property until you hit the type you want. – mdm20 May 11 '09 at 13:51