如何解决Process.Start 打开资源管理器
我正在使用 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>
解决方法
我重新启动了计算机,现在它似乎可以正常工作了。还是谢谢你的帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。