是否可以找到包含 DependencyObject 的程序集和文件?

发布于 2024-07-19 05:32:53 字数 323 浏览 3 评论 0原文

我目前正在为 WPF 开发一个小型本地化框架(甚至不要考虑将我指向 locBAML...),并且想知道是否有可能找到指定 DependencyObject 的包含程序集。

例如:我在文件 Window1.xaml 中有一个 XAML 中的普通窗口定义。 该窗口包含一个 StackPanel,其中包含一个 TextBlock。

当仅引用 TextBlock 时是否可以找出哪个程序集包含 Window1.xaml 文件?

是否还可以找到 xaml 文件的文件名(在本例中为“Window1.xaml”)?

预先致谢并致以诚挚的问候, 3福克斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-07-26 05:32:53

我认为这样的事情会起作用。

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

I think something like this would work.

Window window = Window.GetWindow(YourTextBox);
Assembly assembly = Assembly.GetAssembly(window.GetType());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文