Kaynağa Gözat

注释列表-优化选中问题

OYXH\oyxh 1 yıl önce
ebeveyn
işleme
1630e03eff

+ 39 - 36
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -275,7 +275,8 @@ namespace PDF_Master.ViewModels.BOTA
         public DelegateCommand TimeAscendingCommand { get; set; }
         public DelegateCommand TimeDescendingCommand { get; set; }
         public string Unicode { get; private set; }
-        private bool IsFirst = true;
+        private bool IsFirst = true;
+
         public AnnotationContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
         {
             region = regionManager;
@@ -312,8 +313,8 @@ namespace PDF_Master.ViewModels.BOTA
             colors.Clear();
             authors.Clear();
             annotArgsTypes.Clear();
-            AnnotationListItems.Clear();
-            
+            AnnotationListItems.Clear();
+
             CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
             AnnotationListItems.AddRange(CurrentAnnotationLists);
             Screen = Visibility.Collapsed;
@@ -326,8 +327,8 @@ namespace PDF_Master.ViewModels.BOTA
             authors.Clear();
             annotArgsTypes.Clear();
             AnnotationListItems.Clear();
-           
-            //AnnotationListItems = GetDocumentAnnotionList(out ObservableCollection<AnnotationHandlerEventArgs> HideAnnots);
+
+            //AnnotationListItems = GetDocumentAnnotionList(out ObservableCollection<AnnotationHandlerEventArgs> HideAnnots);
             CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
             AnnotationListItems.AddRange(CurrentAnnotationLists);
             RefreshAnnotationListItems();
@@ -711,8 +712,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 类型 颜色 作者
 
-            #region 颜色 作者
-
+            #region 颜色 作者
+
             else if (colors.Count > 0 && authors.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -732,8 +733,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 颜色 作者
 
-            #region 类型 作者
-
+            #region 类型 作者
+
             else if (annotArgsTypes.Count > 0 && authors.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -753,8 +754,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 类型 作者
 
-            #region 类型 颜色
-
+            #region 类型 颜色
+
             else if (annotArgsTypes.Count > 0 && colors.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -774,8 +775,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 类型 颜色
 
-            #region 类型
-
+            #region 类型
+
             else if (annotArgsTypes.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -792,8 +793,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 类型
 
-            #region 颜色
-
+            #region 颜色
+
             else if (colors.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -807,8 +808,8 @@ namespace PDF_Master.ViewModels.BOTA
 
             #endregion 颜色
 
-            #region 作者
-
+            #region 作者
+
             else if (authors.Count > 0)
             {
                 foreach (var item in CurrentAnnotationLists)
@@ -945,12 +946,12 @@ namespace PDF_Master.ViewModels.BOTA
             if (obj is ListBoxItem listBoxItem)
             {
                 if (listBoxItem.DataContext is AnnotationHandlerEventArgs args)
-                {
-                    //if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink)
-                        if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText &&
-                       args.EventType != AnnotArgsType.AnnotHighlight && args.EventType != AnnotArgsType.AnnotUnderline
-                       && args.EventType != AnnotArgsType.AnnotStrikeout && args.EventType != AnnotArgsType.AnnotLink)
-                        {
+                {
+                    //if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink)
+                    if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText &&
+                   args.EventType != AnnotArgsType.AnnotHighlight && args.EventType != AnnotArgsType.AnnotUnderline
+                   && args.EventType != AnnotArgsType.AnnotStrikeout && args.EventType != AnnotArgsType.AnnotLink)
+                    {
                         DialogParameters value = new DialogParameters();
                         value.Add(ParameterNames.Annotation, args);
                         dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
@@ -1026,11 +1027,14 @@ namespace PDF_Master.ViewModels.BOTA
                     {
                         //需要手动搜寻在哪一个分组 展开分组头
                         ExpandGroupHeader(item, AnnotationList);
-                        AnnotationList.SelectedItem = item;
+                        if (AnnotationList.SelectedItems.IndexOf(item) == -1)
+                        {
+                            AnnotationList.SelectedItem = item;
+                        }
+                            
                         await Task.Delay(1);
                         AnnotationList.ScrollIntoView(item);
-                    }
-                    
+                    }
                 }
             }
         }
@@ -1090,13 +1094,12 @@ namespace PDF_Master.ViewModels.BOTA
                         }
                         ExpandGroupHeader(args, listBox);
                         // 关闭后选中关闭前的位置
-                        if (ViewContentViewModel.OpenBOTA) { 
-                       
-
-                        await Task.Delay(5);//不加延时 会有不滚动的现象
-
-                        //events.GetEvent<ScrollIntoAnnotViewEvent>().Publish(new ScrollIntoAnnotViewArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = item });
-                        listBox.ScrollIntoView(args);
+                        if (ViewContentViewModel.OpenBOTA)
+                        {
+                            await Task.Delay(5);//不加延时 会有不滚动的现象
+
+                            //events.GetEvent<ScrollIntoAnnotViewEvent>().Publish(new ScrollIntoAnnotViewArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = item });
+                            listBox.ScrollIntoView(args);
                         }
                         //if (!listBox.SelectedItems.Contains(args))
                         //{
@@ -1211,14 +1214,14 @@ namespace PDF_Master.ViewModels.BOTA
                             await Task.Delay(5);//不加延时 每页的第一个注释不会展开
                             if (ViewContentViewModel.IsMultiSelected == false)
                             {
-                                if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
+                                if (listBox.SelectedItems.IndexOf(AnnotationListItems[k]) == -1)
+                                //if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
                                 {
                                     listBox.SelectedItem = AnnotationListItems[k];
                                     //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
                                 }
                             }
 
-
                             ExpandGroupHeader(AnnotationListItems[k], listBox);
 
                             await Task.Delay(5);//不加延时 会有不滚动的现象
@@ -1311,7 +1314,7 @@ namespace PDF_Master.ViewModels.BOTA
                 iCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotationHandlerEventArgs.PageIndex)));
                 iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
                 iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
-               
+
                 //按照PageIndex,分组 排序
                 SetGroupHeader(listBox);
                 Screen = Visibility.Collapsed;