简体   繁体   English

如何从dotnet在Windows 10上正确启动Photos应用

[英]How to properly start the Photos app on windows 10 from dotnet

From my WinForms application I can open documents by using this code : 在WinForms应用程序中,可以使用以下代码打开文档:

using (Process process = new Process())
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    process.StartInfo = startInfo;
    startInfo.FileName = fileName;
    process.Start();
}

Now if the variable fileName contains a full path to a .jpg file then in windows 10 it opens with some app called Photos 现在,如果变量fileName包含.jpg文件的完整路径,则在Windows 10中,它将使用名为“ Photos某些应用程序打开
This works, but it has one problem I dont understand. 这可行,但是有一个我不明白的问题。

When I open the picture in windows explorer by doubleclicking on the picture, the app Photos opens and shows the picture. 当我通过双击图片在Windows资源管理器中打开图片时,“ Photos ”应用会打开并显示图片。 It also has navigation buttons on the left/right of the image. 它还在图像的左侧/右侧具有导航按钮。 Using these buttons I can see the prior/next picture in this folder. 使用这些按钮,我可以在此文件夹中查看上一张/下一张图片。
If I choose SlideShow it will show all pictures in this folder 如果选择“ SlideShow放映”,它将显示该文件夹中的所有图片

When I open the picture using the code above, the same app Photos opens and shows the picture, but this time without the navigating buttons on the left/right of the image. 当我使用上面的代码打开图片时,同一应用“ Photos将打开并显示图片,但是这次没有图片左侧/右侧的导航按钮。
If I choose SlideShow it will show only this picture while there are others in this folder. 如果选择“ SlideShow放映”,则此文件夹将仅显示该图片,而该文件夹中还有其他图片。

So my question is, how can I get these navigating buttons back ? 所以我的问题是,我怎样才能找回这些导航按钮?
Also, there can be other file types then .jpg in the variable fileName . 此外,变量fileName可能还有.jpg以外的其他文件类型。
I need a general method that will open each file with the default association set in windows. 我需要一个通用方法,该方法将使用Windows中设置的默认关联打开每个文件。

In windows 7 and 8 this was never a problem, the navigation buttons always appeared. 在Windows 7和Windows 8中,这从来没有问题,导航按钮始终出现。 It only behave this way in windows 10 它仅在Windows 10中以这种方式运行

EDIT 编辑
If I have to use other code to open pictures than for other documents, I am willing to do that. 如果我必须使用其他代码来打开图片而不是其他文档,则我愿意这样做。
I can always check the extension of the file first 我总是可以先检查文件的扩展名

You probably also need to set the working directory of the new process to be the folder that the image is located in. 您可能还需要将新进程的工作目录设置为映像所在的文件夹。

It would look something like this 看起来像这样

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = fileName;
startInfo.WorkingDirectory = Path.GetDirectoryName(fileName);

process.StartInfo = startInfo;
process.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MVC 4应用程序无法在Windows 10上正常运行吗? - MVC 4 app is not working properly on Windows 10? dotnet:适用于 Windows 10 命令提示符,但不适用于 VSCode - dotnet: Works from Windows 10 command prompt, but not in VSCode 如何以编程方式从我的 Windows 10 应用程序启动相机应用程序? - How to launch camera app from my windows 10 app programmatically? 如何从 Windows 8 照片应用程序中获取路径作为共享目标? - How do I get the Path from the Windows 8 Photos App as a Share Target? 全屏启动Windows 10中的Windows 8.1 Store App - Start windows 8.1 Store App in Windows 10 in full screen 如何在Windows 10中正确安装LLVMLITE? - How to properly install LLVMLITE in windows 10? 如何从Windows 10通用应用程序中的CD导入.CDA曲目? - How to import .CDA tracks from a CD in windows 10 universal app? 如何从 Windows 10 UWP 应用程序连接到 SQL 服务器数据库 - How to connect to SQL server database from a Windows 10 UWP app 如何通过Windows 10 Universal应用程序将Firebase与C#连接起来? - How to connect Firebase with C# from a Windows 10 Universal app? 如何从现有的Windows服务启动AspNetCore应用程序 - How to start a AspNetCore App from an existing windows service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM