views:

85

answers:

1

Hi girls and guys!

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

+2  A: 

I think something like this would work.

Window window = Window.GetWindow(YourTextBox);
Assembly assembly = Assembly.GetAssembly(window.GetType());
mdm20
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
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
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
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
You can recursively go up each controls Parent property until you hit the type you want.
mdm20