Process.Start 打开资源管理器
Process.Start opening explorer
我正在使用 C# 开发一个简单的 WPF 图像查看器。我正在添加一项功能,以便您可以右键单击图像以打开文件路径。我正在使用 Process.Start
以路径作为参数打开资源管理器。我的应用程序运行正常,但无法打开资源管理器。
我的 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>
我重新启动了计算机,现在它似乎可以正常工作了。无论如何感谢您的帮助
我正在使用 C# 开发一个简单的 WPF 图像查看器。我正在添加一项功能,以便您可以右键单击图像以打开文件路径。我正在使用 Process.Start
以路径作为参数打开资源管理器。我的应用程序运行正常,但无法打开资源管理器。
我的 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>
我重新启动了计算机,现在它似乎可以正常工作了。无论如何感谢您的帮助