Forráskód Böngészése

其他-修复一次添加多个文件崩溃的问题

ZhouJieSheng 2 éve
szülő
commit
24b8dd77ab

+ 5 - 1
PDF Office/ViewModels/HomeContentViewModel.cs

@@ -93,7 +93,7 @@ namespace PDF_Office.ViewModels
         /// <summary>
         /// 从其他格式文件创建PDF
         /// </summary>
-        private void createFromOtherFile()
+        private async void createFromOtherFile()
         {
             string txt = Properties.Resources.txtex;
             string word = Properties.Resources.wordex;
@@ -123,6 +123,8 @@ namespace PDF_Office.ViewModels
                 {
                     if (!App.OpenedFileList.Contains(fileList[i]))
                     {
+                        //需要加一定延时 不然连续添加多个文件时会出现regionname重名的情况 因为多处导航是异步导航,可能绑定还没更新
+                        await Task.Delay(20);
                         App.mainWindowViewModel.AddTabItem(fileList[i]);
                     }
                     ToolMethod.SetFileThumbImg(fileList[i]);
@@ -181,6 +183,8 @@ namespace PDF_Office.ViewModels
                     {
                         if (!App.OpenedFileList.Contains(fileList[i]))
                         {
+                            //需要加一定延时 不然连续添加多个文件时会出现regionname重名的情况 因为多处导航是异步导航,可能绑定还没更新
+                            await Task.Delay(20);
                             App.mainWindowViewModel.AddTabItem(fileList[i]);
                         }
                         ToolMethod.SetFileThumbImg(fileList[i]);

+ 4 - 4
PDF Office/ViewModels/MainContentViewModel.cs

@@ -157,11 +157,11 @@ namespace PDF_Office.ViewModels
                 { ParameterNames.MainViewModel, this },
                 { ParameterNames.PDFViewer,PDFViewer}
             };
-            //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
-            //{
+            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+            {
                 //if (toolregion.Regions.ContainsRegionWithName(MainContentRegionName))
-                    toolregion.RequestNavigate(MainContentRegionName, "ViewContent", parameters);
-            //}));
+                toolregion.RequestNavigate(MainContentRegionName, "ViewContent", parameters);
+            }));
 
         }