从另一个wpf应用程序打开wpf应用程序窗口时图像不显示 [英] When Opening a wpf application window from another wpf application Image not displaying

查看:141
本文介绍了从另一个wpf应用程序打开wpf应用程序窗口时图像不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个应用程序中存在的windows / Wpf表单打开一个WPF申请表。我有一些功能区按钮和WPF形式的图像。但是通过单击Windows窗体上的按钮打开wpf表单时在运行时出错。当我运行WPF应用程序时,其工作正常。当我没有图像运行时,也工作正常。但是当我添加图像引用时它显示错误



只有在从另一个WINDOWS / WPF应用程序打开WPF应用程序表时才会出现错误.IF有一个相对的图像路径引用

解决方案

这几乎可以肯定是由于你的WPF应用程序的工作目录。



当你启动时从Windows应用程序,工作目录将设置为WPF应用程序的目录。当您从其他应用程序启动它时,它将被设置为您在 ProcessStartInfo 结构中指定的任何内容,并将默认为调用应用程序的目录。



如果你的WPF应用程序试图使用相对路径加载文件,它将相对于工作目录。当工作目录设置为其他应用程序的目录时,它将无法找到这些文件。



确保在启动时明确指定工作目录应用程序:

 Process.Start( new  ProcessStartInfo( @  C:\ Path\To \Your\WPF \ Application \ file.exe
{
WorkingDirectory = @ C:\ Path\To \Your \WPF \ Application \
});


最后我找到答案.....



右键单击图像文件并选择属性。

将构建操作更改为内容。

如果较新,请将复制到输出目录更改为复制。



使用。前路径

使用pack:// siteoforigin



=包装: // siteoforigin:,,, / supportedfiles /资源/图像/ ribbonimages / New.png

Am opening a WPF application form from windows/Wpf form which is exist in another application. I have some ribbon button and its images in WPF form. But getting error on runtime while opening wpf form by clicking a button on windows form . When am running WPF application exe its working fine. When am running without images , also working fine. But when am adding image reference its showing error

ONLY GETTING ERROR WHILE OPENING WPF APPLICATION FORM FROM Another WINDOWS/WPF APPLICATION .IF THERE IS A RELATIVE IMAGE PATH REFERENSE

解决方案

This is almost certainly due to the "working directory" for your WPF application.

When you launch the application from Windows, the working directory will be set to the WPF application's directory. When you launch it from your other application, it will be set to whatever you've specified in the ProcessStartInfo structure, and will default to the calling application's directory.

If your WPF application is trying to load files using a relative path, it will be relative to the working directory. When the working directory is set to the other application's directory, it won't be able to find the files.

Make sure you explicitly specify the working directory when you launch the application:

Process.Start(new ProcessStartInfo(@"C:\Path\To\Your\WPF\Application\file.exe")
{
    WorkingDirectory = @"C:\Path\To\Your\WPF\Application\"
});


Finally i found answer.....

Right-click on your image file and choose Properties.
Change the Build Action to Content.
Change the Copy to Output Directory to Copy if newer.

Use ". " Before path
Use "pack://siteoforigin"

="pack://siteoforigin:,,,./supportedfiles/resources/images/ribbonimages/New.png"


这篇关于从另一个wpf应用程序打开wpf应用程序窗口时图像不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆