首页 新闻 赞助 找找看

WPF OpenFileDialog 一打开“打开文件”对话框程序就退出

0
悬赏园豆:20 [已解决问题] 解决于 2013-04-04 18:32

在vs2010里面调试是好好的。但是生成安装包安装之后,一点击“打开”菜单,程序就退出了。不知道是什么问题。以前重来没碰到过。一下是“打开”菜单的事件函数。哪位碰到过这样的情况???

private void fileMenu_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();
open.Multiselect = false;
open.Filter = "Video Files(*.avi;*.rmvb;*.flv;*.mp4)|*.avi;*.rmvb;*.flv;*.mp4|All Files(*.*)|*.*";
//open.ShowDialog();
if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (null != videoSource && videoSource.IsRunning)
{
videoSource.Stop();
}
if (null == videoSource)
{
videoSource = new AForge.Video.FFMPEG.VideoFileSource(open.FileName);
videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);
}
else
{
videoSource.Source = open.FileName;
}

}
}

xiaxia—博客园的主页 xiaxia—博客园 | 初学一级 | 园豆:128
提问于:2012-09-23 20:52
< >
分享
最佳答案
0

我觉得是你在WPF程序中使用了Winform的OpenFileDialog类的原因的, 你可以Microsoft.Win32.OpenFileDialog 这个类来测试下(使用这个方式来选择文件应该不会有问题的),也可以使用链接文章中提出的使用多线程来测试下的( http://www.silverlightchina.net/html/study/WPF/2012/0330/14980.html ),你这个问题应该是出现了StackOverflowException异常的

收获园豆:20
Learning hard | 菜鸟二级 |园豆:362 | 2012-09-24 00:00

补充下(Microsoft.Win32.OpenFileDialog 类的使用):

Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
ofd.Filter = "xml file|*.xml";
if (ofd.ShowDialog() == true)
{
    // 把 if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)中的语句放在这里就好了
{
}
Learning hard | 园豆:362 (菜鸟二级) | 2012-09-24 00:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册