Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Comments
VR Karthikeyan 8-Oct-15 12:24pm    
Show your code.
Sergey Alexandrovich Kryukov 8-Oct-15 13:51pm    
Probably you think that starting one application from another one is a kind of "integration", but this is not. And a decent application's behavior does not depend on the parent process; having such issue means that your child application is not "working fine", you only have a false impression. I don't understand what kind of help could you expect with such "question". There is nothing to discuss here.
—SA

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:
C#
Process.Start(new ProcessStartInfo(@"C:\Path\To\Your\WPF\Application\file.exe")
{
    WorkingDirectory = @"C:\Path\To\Your\WPF\Application\"
});
 
Share this answer
 
Comments
nijilmk 9-Oct-15 1:50am    
Hard coded path?
Richard Deeming 9-Oct-15 7:54am    
What?
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"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900