C#wpf Process.start赢得';没有断点就不能工作
下面是我的代码:C#wpf Process.start赢得';没有断点就不能工作,c#,C#,下面是我的代码: public static void ImageDoubleClick(FileModel file) { if (file == null) { return; } Process.Start(new ProcessStartInfo(file.FileName) { UseS
public static void ImageDoubleClick(FileModel file)
{
if (file == null)
{
return;
}
Process.Start(new ProcessStartInfo(file.FileName)
{
UseShellExecute = true
});
}
当我双击该图像时,它将使用system shell打开该文件。但是当我双击的时候。什么事都没有发生,好像我没有触发这件事似的。但我知道是的
所以我在“Process.Start”行添加了一个断点。它确实停止了。然后,如果我单击“继续”,文件将被正确打开
我错过了什么?谢谢你的帮助
xaml的代码是:
<ContentControl VerticalAlignment="Center"
cal:Message.Attach="[Event MouseDoubleClick]=[Action ImageDoubleClick($dataContext)]">
<StackPanel x:Name="border"
VerticalAlignment="Center"
cal:Message.Attach="[Event MouseLeftButtonUp]=[Action ImageClick($dataContext)]"
Orientation="Horizontal">
<Border Height="25" Width="25">
<StackPanel>
<Canvas Width="24" Height="24"
HorizontalAlignment="Center"
VerticalAlignment="Center"
>
<Canvas.Background>
<ImageBrush ImageSource="{Binding FileImage}"
AlignmentX="Center"
AlignmentY="Center"
Stretch="Fill" />
</Canvas.Background>
<CheckBox Name="myCheckBox"
IsChecked="{Binding IsSelected}"
Visibility="Collapsed" />
</Canvas>
</StackPanel>
</Border>
<StackPanel HorizontalAlignment="Left"
VerticalAlignment="Center"
Visibility="{Binding ImageTextEnabled, Converter={StaticResource VisibleIfTrueConverter}}"
>
<TextBlock Text="{Binding DisplayName}"
FontFamily="Microsoft YaHei, Arial"
FontSize="7"
FontWeight="Bold"
Foreground="Black"
Style="{StaticResource MaterialDesignOverlineTextBlock}"
TextWrapping="NoWrap"
HorizontalAlignment="Left" VerticalAlignment="Center"
Margin="5,0,0,0"
Width="200" />
<TextBlock Text="{Binding CreatedDateTime, Mode=OneWay, StringFormat='yyyy-MM-dd HH:mm:ss'}"
FontFamily="Microsoft YaHei, Arial"
FontSize="7"
FontWeight="Bold"
Foreground="Gray"
Style="{StaticResource MaterialDesignOverlineTextBlock}"
TextWrapping="NoWrap"
HorizontalAlignment="Left" VerticalAlignment="Center"
Margin="5,0,0,0"
Width="200" />
</StackPanel>
</StackPanel>
</ContentControl>
我只是尝试了一下,并发现这段代码在编译后运行得很好。它只是在VisualStudio2019调试模式下工作异常。不知道出了什么问题。(不是回答而是选择)
你的活动在哪里?如果没有可靠地再现问题的好方法,就不可能提供好的答案。也就是说,您尝试打开的图像文件很可能是您在程序本身中创建的图像文件,并且在您尝试通过
进程
打开它之前,您未能完全关闭该文件并释放其文件句柄。因此,当shell试图代表进程
打开文件时,它会失败,因为文件被锁定。当你调试时,你会放慢速度使它工作。如果你认为问题出在其他方面,请改进帖子。另请参见。@Clint,这是MVVM,这就是事件。@Peter Duniho。它不会被锁上。因为在此步骤之前我不会打开文件。图像只是表示文件的图像。然后修复您的问题,使其包含正确的。目前无法解释您描述的行为。谢谢您的回答,但我必须在我的流程中添加“UseShellExecute”。请这样尝试,myProcess.StartInfo.UseShellExecute=false;myProcess.StartInfo.FileName=file.FileName;myProcess.StartInfo.CreateNoWindow=true;myProcess.Start();检查文件名是否无效否。如果文件名为空,它将返回。如果无效,则为例外。在stop.shell出现问题后,它确实起了作用,所以我更喜欢直接传递到CMD
System.Diagnostics.Process.Start(file.FileName);