簡體   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