为什么Process.Start方法始终显示“打开方式”对话框

时间:2020-09-25 07:21:03

标签: c# wpf process.start

我正在使用WPF应用程序,该应用程序使用Process.Start()方法通过默认查看器应用程序打开图像和PDF文件。

出什么问题了?

每次我调用Process.Start()方法时,即使我选中“始终使用此应用程序打开.jpg文件”选项,也会显示“打开方式”对话框。

这是我的C#代码:

public void Open(string fileName, bool isPdf)
{
    var sharedFolderPath = AppCore.Settings.SharedFolder.Path;
    string message;

    if (sharedFolderPath is null)
    {
        message = Resources.EmptySharedFolderErrorMessage;
        AppCore.ShowDialog(AppCore.GetMessageDialog(message));
        return;
    }

    var path = Path.Combine(sharedFolderPath, fileName);

    if (File.Exists(path))
    {
        try
        {
            if (isPdf || AppCore.Settings.ImageViewerSettings.OpenInWindowsDefaultApp)
            {
                Process.Start(path);
            }
            else
            {
                var imageViewerWindow = new ImageViewerWindow(path);
                imageViewerWindow.ShowDialog();
            }
        }
        catch (Exception ex)
        {
            AppCore.Logger.Info("Opening shared file failed.");
            AppCore.Logger.Exception(ex);
        }

        return;
    }

    message = string.Format(Resources.SharedFolderFileNotFoundMessage, fileName);
    AppCore.ShowDialog(AppCore.GetMessageDialog(message));
}

我的问题有更多详细信息: https://imgur.com/a/JQyIMZE

已编辑

我创建了一个简单的WPF项目,并尝试使用Process.Start()方法打开图像。在新项目中,该图片是使用默认应用打开的,没有显示“打开方式”对话框。

1 个答案:

答案 0 :(得分:0)

我不知道为什么/如何,但是在卸载昨天安装的 TechSmith Snagit 后,我的问题解决了。

相关问题