“无法定位资源”再次
我有一个应用程序可以动态加载带有用户控件的 dll。在其中一个 dll 中,我有一个控件,它显示一个按钮,点击该按钮时,会弹出一个新窗口。一切都会很好,但窗口没有出现...我得到的只是“无法定位资源 XXX.xaml”消息,其中包含定义要弹出的窗口的 xaml 名称。
要弹出的窗口是在绑定到按钮的命令中创建的:
private void onCmdSetIndexValidator(object _param) {
IIndex param = (IIndex)_param;
new IndexValidatorsEditor(param).Show();
}
有什么想法吗?
I have an application which loads dlls with user controls dynamically. Inside one of the dlls I have a control which shows a button, which, when hit, pops up a new window. Everything would be great but the window does not appear... all I get is the "Cannot locate resource XXX.xaml" message with the name of the xaml which defines the window to pop up.
The window to pop up is created in a command which is binded to the button:
private void onCmdSetIndexValidator(object _param) {
IIndex param = (IIndex)_param;
new IndexValidatorsEditor(param).Show();
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
窗口中的资源需要确定它们所在的程序集的范围。如果您访问窗口中的资源(图像、页面等),则需要指定它来自的程序集(即使它来自其自己的程序集)。如果您不指定程序集,WPF 将假定资源来自执行程序集(您的客户端应用程序)。
通过 pack URI 定义程序集。示例:
/nameOfAssembly;component/folder/background.png
它也可能有助于查看原始异常的内部异常值。有时,这可以提供有关其无法定位哪些资源的线索。
http://msdn.microsoft.com/en-us/library/aa970069.aspx
Resources in the Window need to be scoped for the assembly where they live. If you access an asset in your Window (Image, Page, etc), you need to specify the assembly it comes from (even if it comes from its own assembly). If you do not specify the assembly, WPF will assume the resource comes from the executing assembly (your client app).
Define the assembly via pack URI's. Example:
/nameOfAssembly;component/folder/background.png
It also may help to look at the inner exception value of the original exception. Sometimes this provides clues as to what resource its having trouble locating.
http://msdn.microsoft.com/en-us/library/aa970069.aspx
解决方案很简单...加载我的 dll 的代码是错误的 - 它使用 Assembly.LoadFile 而不是 Assembly.LoadFrom
The solution was simple... the code which loaded my dll was wrong - it used Assembly.LoadFile instead of Assembly.LoadFrom