繁体   English   中英

Process.Start 打开资源管理器

[英]Process.Start opening explorer

我正在使用 c# 开发一个简单的 WPF 图像查看器。 我正在添加一项功能,因此您可以右键单击图像以打开文件路径。 我正在使用Process.Start打开路径为 arguments 的资源管理器。 我的应用程序运行良好,但无法打开资源管理器。

我的 c# 代码是

        string selectedFileName;
        string directoryPath;

        private void MenuItemFromFile_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image Files (*.jpg|*.jpg|*.gif|*.ico|*.bmp|*.png|*.wdp| .tiff)|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 8;


            
            if (openFileDialog.ShowDialog() == true)
            {
                selectedFileName = openFileDialog.FileName;
                directoryPath = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
                
                BitmapImage bitmap = new BitmapImage();  
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(selectedFileName);  
                bitmap.EndInit();
                FullImage.Source = bitmap;
            }
        }

        private void ContextItemFileLocation_OnClick(object sender, RoutedEventArgs e)
        {

            Process.Start("C:\\Windows\\explorer.exe", @directoryPath);
        }

我的 XAML

        <Image Grid.Row="2" 
               Grid.Column="1" 
               Name = "FullImage" 
               Stretch="Uniform" 
               StretchDirection="Both" >
            <Image.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="open file location" 
                              Name="ContextItemFileLocation" 
                              Click="ContextItemFileLocation_OnClick"/>
                </ContextMenu>
            </Image.ContextMenu>
            
        </Image>

我重新启动了我的计算机,它现在似乎可以工作了。 无论如何感谢您的帮助

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM