Bladeren bron

注释-链接-定位带目标范围

OYXH\oyxh 2 jaren geleden
bovenliggende
commit
c958b69620

+ 33 - 34
PDF Office/Styles/ButtonStyle.xaml

@@ -17,14 +17,19 @@
             </Setter.Value>
         </Setter>
     </Style>
-    <Style
-        x:Key="PageEditToolBtn"
-        BasedOn="{StaticResource TitleBarBtn}"
-        TargetType="{x:Type Button}">
-        <Setter Property="Background" Value="Transparent" />
-        <Setter Property="BorderBrush" Value="Transparent" />
-        <Setter Property="Width" Value="auto" />
-        <Setter Property="Height" Value="40" />
+
+    <Style x:Key="TitleBarBtn" TargetType="{x:Type Button}">
+        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
+        <Setter Property="Background" Value="{StaticResource Button.Static.Background}" />
+        <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}" />
+        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
+        <Setter Property="BorderThickness" Value="0" />
+        <Setter Property="HorizontalContentAlignment" Value="Center" />
+        <Setter Property="VerticalContentAlignment" Value="Center" />
+        <Setter Property="Padding" Value="0" />
+        <Setter Property="Width" Value="32" />
+        <Setter Property="Height" Value="32" />
+        <Setter Property="IsTabStop" Value="False" />
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Button}">
@@ -45,36 +50,30 @@
                     </Border>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsMouseOver" Value="true">
-                            <Setter TargetName="border" Property="Background" Value="#1A000000" />
+                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
                             <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.MouseOver.Border}" />
                         </Trigger>
                         <Trigger Property="IsPressed" Value="true">
-                            <Setter TargetName="border" Property="Background" Value="#26000000" />
+                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
                             <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Pressed.Border}" />
                         </Trigger>
                         <Trigger Property="IsEnabled" Value="false">
-                            <Setter TargetName="border" Property="Background" Value="Transparent" />
-                            <Setter TargetName="border" Property="BorderBrush" Value="#33000000" />
-                            <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="#FF999999" />
-                            <Setter TargetName="contentPresenter" Property="Opacity" Value="0.4" />
+                            <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{StaticResource Button.Disabled.Foreground}" />
+                            <Setter TargetName="contentPresenter" Property="Opacity" Value="0.5" />
                         </Trigger>
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
-    <Style x:Key="TitleBarBtn" TargetType="{x:Type Button}">
-        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
-        <Setter Property="Background" Value="{StaticResource Button.Static.Background}" />
-        <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}" />
-        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
-        <Setter Property="BorderThickness" Value="0" />
-        <Setter Property="HorizontalContentAlignment" Value="Center" />
-        <Setter Property="VerticalContentAlignment" Value="Center" />
-        <Setter Property="Padding" Value="0" />
-        <Setter Property="Width" Value="32" />
-        <Setter Property="Height" Value="32" />
-        <Setter Property="IsTabStop" Value="False" />
+    <Style
+        x:Key="PageEditToolBtn"
+        BasedOn="{StaticResource TitleBarBtn}"
+        TargetType="{x:Type Button}">
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="BorderBrush" Value="Transparent" />
+        <Setter Property="Width" Value="auto" />
+        <Setter Property="Height" Value="40" />
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Button}">
@@ -95,23 +94,24 @@
                     </Border>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsMouseOver" Value="true">
-                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
+                            <Setter TargetName="border" Property="Background" Value="#1A000000" />
                             <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.MouseOver.Border}" />
                         </Trigger>
                         <Trigger Property="IsPressed" Value="true">
-                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
+                            <Setter TargetName="border" Property="Background" Value="#26000000" />
                             <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Pressed.Border}" />
                         </Trigger>
                         <Trigger Property="IsEnabled" Value="false">
-                            <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{StaticResource Button.Disabled.Foreground}" />
-                            <Setter TargetName="contentPresenter" Property="Opacity" Value="0.5" />
+                            <Setter TargetName="border" Property="Background" Value="Transparent" />
+                            <Setter TargetName="border" Property="BorderBrush" Value="#33000000" />
+                            <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="#FF999999" />
+                            <Setter TargetName="contentPresenter" Property="Opacity" Value="0.4" />
                         </Trigger>
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
-
     <Style
         x:Key="CloseBtn"
         BasedOn="{StaticResource TitleBarBtn}"
@@ -198,7 +198,6 @@
         </Setter>
     </Style>
 
-
     <Style x:Key="NoColorBtn" TargetType="{x:Type Button}">
         <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
@@ -391,8 +390,8 @@
     </ControlTemplate>
 
     <!--
-        Style for Btn.cta
-        样式里仅设置了背景色和文字颜色变化,字体大小和控件宽度需要调用时设置
+    Style for Btn.cta
+    样式里仅设置了背景色和文字颜色变化,字体大小和控件宽度需要调用时设置
     -->
     <Style x:Key="Btn.cta" TargetType="{x:Type Button}">
         <Setter Property="FocusVisualStyle" Value="{x:Null}" />

+ 1 - 1
PDF Office/Styles/CheckBoxStyle.xaml

@@ -105,7 +105,7 @@
             </Trigger>
         </ControlTemplate.Triggers>
     </ControlTemplate>
-    
+
     <Style x:Key="EditToolsCheckBoxStyle" TargetType="{x:Type CheckBox}">
         <Setter Property="SnapsToDevicePixels" Value="true" />
         <Setter Property="OverridesDefaultStyle" Value="False" />

+ 1 - 1
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -423,7 +423,7 @@ namespace PDF_Office.ViewModels.BOTA
             if (AnnotationListItems.Count > 0)
             {
                 IsEmptyPanelVisibility = Visibility.Collapsed;
-                await Task.Delay(10);
+                await Task.Delay(2);
                 //展开数据
                 ExpandGroupHeader(AnnotationListItems, listBox);
             }

+ 71 - 68
PDF Office/ViewModels/Dialog/BOTA/ScreenAnnotationDialogViewModel.cs

@@ -138,6 +138,20 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
             }
         }
 
+        /// <summary>
+        /// 链接
+        /// </summary>
+        private Visibility annotLinkVisible;
+
+        public Visibility AnnotLinkVisible
+        {
+            get { return annotLinkVisible; }
+            set
+            {
+                SetProperty(ref annotLinkVisible, value);
+            }
+        }
+
         /// <summary>
         /// 矩形
         /// </summary>
@@ -237,9 +251,12 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
         private CustomIconToggleBtn btnAnnotFreeText = null;
         private CustomIconToggleBtn btnAnnotStrikeout = null;
         private CustomIconToggleBtn btnUnderLine = null;
+        private CustomIconToggleBtn btnAnnotLink = null;
+
         private ListBox _ListColor = null;
         private ListBox _ListAuthor = null;
 
+        private List<CustomIconToggleBtn> iconToggleBtns = new List<CustomIconToggleBtn>();
         private List<string> colors = new List<string>();
         private List<string> authors = new List<string>();
         private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
@@ -273,6 +290,11 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                     btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
                     btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
                     btnUnderLine = arrys[10] as CustomIconToggleBtn;
+                    btnAnnotLink = arrys[11] as CustomIconToggleBtn;
+                    for (int i = 0; i < arrys.Length - 2; i++)
+                    {
+                        iconToggleBtns.Add(arrys[i] as CustomIconToggleBtn);
+                    }
                     SetBtnSelectedState(arrys);
                 }
             }
@@ -359,6 +381,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                             break;
 
                         case AnnotArgsType.AnnotLink:
+                            SetBtnType(btnAnnotLink, false);
                             break;
 
                         case AnnotArgsType.AnnotSelectTool:
@@ -388,7 +411,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                 }
             }
 
-            if (arrys[11] is System.Windows.Controls.ListBox listColor)
+            if (arrys[12] is System.Windows.Controls.ListBox listColor)
             {
                 this._ListColor = listColor;
 
@@ -408,7 +431,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                     }
                 }
             }
-            if (arrys[12] is System.Windows.Controls.ListBox listAuthor)
+            if (arrys[13] is System.Windows.Controls.ListBox listAuthor)
             {
                 this._ListAuthor = listAuthor;
 
@@ -436,44 +459,22 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
         /// <param name="obj"></param>
         private void CleanEvent(Object obj)
         {
-            if (obj is Object[] arrys)
-            {
-                //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
-                //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
-
-                SetBtnType(btnHighlight, true);
-                SetBtnType(btnFreeHand, true);
-                SetBtnType(btnAnnotSticky, true);
-                SetBtnType(btnAnnotStamp, true);
-                SetBtnType(btnSharpLine, true);
-                SetBtnType(btnSharpArrow, true);
-                SetBtnType(btnAnnotCircle, true);
-                SetBtnType(btnAnnotSquare, true);
-                SetBtnType(btnAnnotFreeText, true);
-                SetBtnType(btnAnnotStrikeout, true);
-                SetBtnType(btnUnderLine, true);
-
-                if (this._ListColor != null)
-                {
-                    this._ListColor.SelectedItems.Clear();
-                }
-                if (this._ListAuthor != null)
-                {
-                    this._ListAuthor.SelectedItems.Clear();
-                }
-                DialogParameters valuePairs = new DialogParameters();
-                valuePairs.Add(ParameterNames.AnnotationCleanState, true);
-                RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
-            }
+            //for (int i = 0; i < iconToggleBtns.Count; i++)
+            //{
+            //    SetBtnType(iconToggleBtns[i], true);
+            //}
+
+            //if (this._ListColor != null)
+            //{
+            //    this._ListColor.SelectedItems.Clear();
+            //}
+            //if (this._ListAuthor != null)
+            //{
+            //    this._ListAuthor.SelectedItems.Clear();
+            //}
+            DialogParameters valuePairs = new DialogParameters();
+            valuePairs.Add(ParameterNames.AnnotationCleanState, true);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
         }
 
         /// <summary>
@@ -497,43 +498,40 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
         /// <param name="obj"></param>
         private void OkEvent(Object obj)
         {
-            if (obj is Object[] arrys)
+            List<AnnotArgsType> styleDic = GetAnnotArgsType();
+            //ListBox listColor = arrys[11] as ListBox;
+            //ListBox listAuthor = arrys[12] as ListBox;
+            List<string> colors = new List<string>();
+            List<string> authors = new List<string>();
+            if (this._ListColor != null)
             {
-                List<AnnotArgsType> styleDic = GetAnnotArgsType(arrys);
-                //ListBox listColor = arrys[11] as ListBox;
-                //ListBox listAuthor = arrys[12] as ListBox;
-                List<string> colors = new List<string>();
-                List<string> authors = new List<string>();
-                if (this._ListColor != null)
+                if (this._ListColor.SelectedItems.Count > 0)
                 {
-                    if (this._ListColor.SelectedItems.Count > 0)
+                    foreach (var item in this._ListColor.SelectedItems)
                     {
-                        foreach (var item in this._ListColor.SelectedItems)
-                        {
-                            ColorItem color = item as ColorItem;
-                            colors.Add(color.Color.ToString());
-                        }
+                        ColorItem color = item as ColorItem;
+                        colors.Add(color.Color.ToString());
                     }
                 }
-                if (this._ListAuthor != null)
+            }
+            if (this._ListAuthor != null)
+            {
+                if (this._ListAuthor.SelectedItems.Count > 0)
                 {
-                    if (this._ListAuthor.SelectedItems.Count > 0)
+                    foreach (var item in this._ListAuthor.SelectedItems)
                     {
-                        foreach (var item in this._ListAuthor.SelectedItems)
-                        {
-                            AuthorItem author = item as AuthorItem;
-                            authors.Add(author.Name);
-                        }
+                        AuthorItem author = item as AuthorItem;
+                        authors.Add(author.Name);
                     }
                 }
-
-                DialogParameters valuePairs = new DialogParameters();
-                valuePairs.Add(ParameterNames.AnnotArgsTypes, styleDic);
-                valuePairs.Add(ParameterNames.AnnotationColors, colors);
-                valuePairs.Add(ParameterNames.AnnotationAuthor, authors);
-                valuePairs.Add(ParameterNames.AnnotationCleanState, false);
-                RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
             }
+
+            DialogParameters valuePairs = new DialogParameters();
+            valuePairs.Add(ParameterNames.AnnotArgsTypes, styleDic);
+            valuePairs.Add(ParameterNames.AnnotationColors, colors);
+            valuePairs.Add(ParameterNames.AnnotationAuthor, authors);
+            valuePairs.Add(ParameterNames.AnnotationCleanState, false);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
         }
 
         /// <summary>
@@ -541,7 +539,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
         /// </summary>
         /// <param name="arrys"></param>
         /// <returns></returns>
-        private List<AnnotArgsType> GetAnnotArgsType(object[] arrys)
+        private List<AnnotArgsType> GetAnnotArgsType()
         {
             List<AnnotArgsType> styleDic = new List<AnnotArgsType>();
             //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
@@ -566,6 +564,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
             GetBtnAnnotArgsTypeState(btnAnnotFreeText, styleDic, AnnotArgsType.AnnotFreeText);
             GetBtnAnnotArgsTypeState(btnAnnotStrikeout, styleDic, AnnotArgsType.AnnotStrikeout);
             GetBtnAnnotArgsTypeState(btnUnderLine, styleDic, AnnotArgsType.AnnotUnderline);
+            GetBtnAnnotArgsTypeState(btnAnnotLink, styleDic, AnnotArgsType.AnnotLink);
             return styleDic;
         }
 
@@ -747,6 +746,10 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                         }
                         AnnotCircleVisibility = Visibility.Visible;
                         break;
+
+                    case AnnotArgsType.AnnotLink:
+                        AnnotLinkVisible = Visibility.Visible;
+                        break;
                 }
             }
 

+ 164 - 73
PDF Office/ViewModels/PropertyPanel/AnnotPanel/LinkAnnotPropertyViewModel.cs

@@ -37,9 +37,6 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
     {
         public AnnotAttribEvent AnnotAttribEvent { get; set; }
 
-        private AnnotPropertyPanel PropertyPanel;
-        private AnnotArgsType annotType;
-
         private LinkAnnotArgs linkAnnotArgs;
 
         public LinkAnnotArgs LinkAnnotArgs
@@ -64,6 +61,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        private AnnotArgsType annotType;
+
         public AnnotArgsType AnnotType
         {
             get { return annotType; }
@@ -415,7 +414,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         private bool isLoaded = false;
         private bool isMail = false;
-        private bool isTextChanged = false;
+        private bool isSelected = false;
+
         private string historyBtnGOorBackTag = string.Empty;
         private int totalPage = 0;
         private int backPageIndex = 0;
@@ -425,6 +425,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         private CPDFDocument document;
         private Button btnGOorBack = null;
         private LinkAnnotProperty linkAnnot;
+        private AnnotPropertyPanel propertyPanel;
+        private ViewContentViewModel viewContentViewModel;
+
+        #region 命令
+
         public DelegateCommand<object> LoadedCommand { get; set; }
         public DelegateCommand<object> PageNumTextLostFocusCommand { get; set; }
 
@@ -434,6 +439,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public DelegateCommand<object> ToggleButtonTabCommand { get; set; }
 
+        #endregion 命令
+
         public LinkAnnotPropertyViewModel()
         {
             LoadedCommand = new DelegateCommand<object>(Loaded);
@@ -445,6 +452,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             isLoaded = true;
         }
 
+        /// <summary>
+        /// 页码文本框 Enter键
+        /// </summary>
+        /// <param name="obj"></param>
         private void PageNumTextKeyDown(object obj)
         {
             if (obj is KeyEventArgs keyEventArgs)
@@ -456,29 +467,45 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 页码文本框失去焦点
+        /// </summary>
+        /// <param name="obj"></param>
         private void PageNumTextLostFocus(object obj)
         {
             if (!string.IsNullOrEmpty(PageNumTextContent))
             {
                 if (CheckPageNumVaild(out int pageNum, PageNumTextContent))
                 {
+                    //isSelected = true;
+
                     AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
                     AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageNum - 1);
                     AnnotAttribEvent?.UpdateAnnot();
 
-                    LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
                     //isTextChanged = false;
                     SetImagePreview(LinkAnnotArgs.DestIndex);
+                    //ImagePreviewVisibility = Visibility.Collapsed;
+                    //BtnGOorBackVisibility= Visibility.Collapsed;
                     BtnLocationIsEnabled = false;
+
+                    LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
+
+                    SelectAnnotation();
                 }
                 else
                 {
                     ImagePreviewVisibility = Visibility.Collapsed;
                     BtnGOorBackVisibility = Visibility.Collapsed;
+                    isSelected = false;
                 }
             }
         }
 
+        /// <summary>
+        /// 模块选择
+        /// </summary>
+        /// <param name="obj"></param>
         private void ToggleButtonTabSelected(object obj)
         {
             if (obj is RadioButton radioButton)
@@ -506,65 +533,69 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                         break;
 
                     case "Web":
-                        LinkAnnotArgs.LinkType = LINK_TYPE.URI;
-                        LinkAnnotArgs.URI = string.Empty;
-                        AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
-                        AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
                         isMail = false;
-                        if (btnGOorBack != null)
-                        {
-                            historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
-                            ChangeBtnGOorBack("GO", btnGOorBack);
-                        }
+                        SetLinkType_URIState("Web");
 
-                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
                         break;
 
                     case "Mail":
-                        LinkAnnotArgs.LinkType = LINK_TYPE.URI;
-                        LinkAnnotArgs.URI = string.Empty;
-                        AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
-                        AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
                         isMail = true;
-                        if (btnGOorBack != null)
+                        SetLinkType_URIState("Mail");
+
+                        break;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 设置BtnGOorBack状态
+        /// </summary>
+        /// <param name="uri"></param>
+        private void SetLinkType_URIState(string uri)
+        {
+            LinkAnnotArgs.LinkType = LINK_TYPE.URI;
+            LinkAnnotArgs.URI = string.Empty;
+            AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
+            AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
+
+            if (btnGOorBack != null)
+            {
+                historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
+                //ChangeBtnGOorBack("GO", btnGOorBack);
+                switch (uri)
+                {
+                    case "Web":
+                        if (!string.IsNullOrEmpty(PageWebTextContent))
                         {
-                            historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
                             ChangeBtnGOorBack("GO", btnGOorBack);
                         }
-                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
 
+                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
                         break;
 
-                    default:
-                        LinkAnnotArgs.LinkType = LINK_TYPE.GOTO;
-                        AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.GOTO;
-                        isMail = false;
-                        if (btnGOorBack != null)
+                    case "Mail":
+                        if (!string.IsNullOrEmpty(PageMailTextContent))
                         {
-                            if (!string.IsNullOrEmpty(historyBtnGOorBackTag))
-                            {
-                                ChangeBtnGOorBack(historyBtnGOorBackTag, btnGOorBack);
-                            }
-                            else
-                            {
-                                ChangeBtnGOorBack("GO", btnGOorBack);
-                            }
+                            ChangeBtnGOorBack("GO", btnGOorBack);
                         }
-                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageNumTextContent) ? Visibility.Collapsed : Visibility.Visible;
+
+                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
                         break;
                 }
             }
         }
 
         /// <summary>
-        /// 定位
+        /// 定位目标范围
         /// </summary>
         /// <param name="obj"></param>
         private void LocationPage(object obj)
         {
+            pdfViewer.EnableDrawSelectArea(true);
             historyPageIndex = pdfViewer.CurrentIndex;
             PageNumTextIsEnabled = false;
-            pdfViewer.EnableDrawSelectArea(true);
+            isSelected = false;
+            viewContentViewModel.LinkAnnotTipVisibility=Visibility.Visible;
         }
 
         /// <summary>
@@ -600,6 +631,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 保存邮件链接
+        /// </summary>
         private void LinkMailSave()
         {
             if (CheckPageMailVaild(PageMailTextContent))
@@ -614,6 +648,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 保存web链接
+        /// </summary>
         private void LinkWebSave()
         {
             if (CheckPageWebVaild(PageWebTextContent))
@@ -639,6 +676,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 页码链接 GoOrBack
+        /// </summary>
         private void LinkPageGoOrBack()
         {
             int pageIndex = Convert.ToInt32(PageNumTextContent) - 1;
@@ -656,8 +696,28 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
             else
             {
-                pdfViewer.GoToPage(historyPageIndex);
-                ChangeBtnGOorBack("GO", btnGOorBack);
+                if (historyPageIndex != -1)
+                {
+                    SelectAnnotation();
+                    pdfViewer.GoToPage(historyPageIndex);
+                    ChangeBtnGOorBack("GO", btnGOorBack);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 选择注释
+        /// </summary>
+        private void SelectAnnotation()
+        {
+            if (linkAnnotArgs != null && !isSelected && linkAnnotArgs.AnnotIndex >= 0)
+            {
+                pdfViewer.SelectAnnotation(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
+                isSelected = true;
+            }
+            else
+            {
+                isSelected = false;
             }
         }
 
@@ -685,24 +745,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-        private void PageNumTextChanged(object obj)
-        {
-            if (obj is TextChangedEventArgs textChangedEventArgs)
-            {
-                if (textChangedEventArgs.Source is TextBoxWithTip textBox)
-                {
-                    int pageNum = -1;
-                    //if (CheckPageNumVaild(out pageNum))
-                    //{
-                    //    if (AnnotArgs != null)
-                    //    {
-                    //        AnnotArgs.DestIndex = pageNum - 1;
-                    //        SetImagePreview();
-                    //    }
-                    //}
-                }
-            }
-        }
+        
 
         /// <summary>
         /// 页码格式验证
@@ -741,6 +784,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             return true;
         }
 
+        /// <summary>
+        /// web链接格式验证
+        /// </summary>
+        /// <param name="text"></param>
+        /// <returns></returns>
         private bool CheckPageWebVaild(string text)
         {
             BtnGOorBackVisibility = Visibility.Collapsed;
@@ -771,6 +819,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             return true;
         }
 
+        /// <summary>
+        /// 邮箱链接格式验证
+        /// </summary>
+        /// <param name="text"></param>
+        /// <returns></returns>
         private bool CheckPageMailVaild(string text)
         {
             BtnGOorBackVisibility = Visibility.Collapsed;
@@ -833,12 +886,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         /// <param name="e"></param>
         private void linkAnnotArgs_LinkDrawFinished(object sender, bool e)
         {
-            //linkAnnot.SetTextBoxEnableOrNot(e, totalPage);
-            //AnnotArgs.DestIndex = -1;
-            //AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] =- 1;
             SetTextBoxEnableOrNot(e, totalPage);
-
-            //AnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
         }
 
         private void Loaded(object obj)
@@ -864,16 +912,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
+            navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanel);
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
+            navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
 
-            if (PropertyPanel != null && pdfViewer != null)
+            if (propertyPanel != null && pdfViewer != null)
             {
                 pdfViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
 
                 pdfViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
-                AnnotAttribEvent = PropertyPanel.AnnotEvent;
-                AnnotType = PropertyPanel.annot.EventType;
+                AnnotAttribEvent = propertyPanel.AnnotEvent;
+                AnnotType = propertyPanel.annot.EventType;
 
                 document = pdfViewer.Document;
                 totalPage = pdfViewer.Document.PageCount;
@@ -909,12 +958,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
                 if (LinkAnnotArgs == null)
                 {
-                    LinkAnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
+                    LinkAnnotArgs = (LinkAnnotArgs)propertyPanel.annot;
                 }
             }
         }
 
-        private void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
+        /// <summary>
+        /// 定位目标范围完成时,触发
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private async void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
         {
             if (e.NotifyType == CustomNotifyType.LinkAreaLocate)
             {
@@ -928,22 +982,31 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                         linkArgs.DestIndex = areaInfo.PageIndex;
                         linkArgs.DestinationPos = new System.Windows.Point(areaInfo.Area.X, pageSize.Height - areaInfo.Area.Y);
 
+                        LinkAnnotArgs = linkArgs;
+                        LinkAnnotArgs.PageIndex = historyPageIndex;
+
                         AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
                         AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
                         AnnotAttribEvent?.UpdateAnnot();
 
-                        linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
+                        LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
 
-                        pdfViewer.GoToPage(historyPageIndex);
-                        LinkAnnotArgs = linkArgs;
-                        LinkAnnotArgs.PageIndex = historyPageIndex;
                         PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
                         SetImagePreview(areaInfo.PageIndex);
+
+                        await System.Threading.Tasks.Task.Delay(2);
+                        SelectAnnotation();
+
+                        pdfViewer.GoToPage(historyPageIndex);
+                        viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
                     }
                 }
             }
         }
 
+        /// <summary>
+        /// 选择链接后,显示参数
+        /// </summary>
         private void GetAnnotAttribute()
         {
             if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
@@ -1061,6 +1124,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 设置文本框和按钮的属性
+        /// </summary>
+        /// <param name="enable"></param>
+        /// <param name="totalPage"></param>
         private void SetTextBoxEnableOrNot(bool enable, int totalPage)
         {
             this.totalPage = totalPage;
@@ -1086,6 +1154,16 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             BtnLocationIsEnabled = enable;
         }
 
+        /// <summary>
+        /// 将PDF的页面转换成数据流
+        /// </summary>
+        /// <param name="document"></param>
+        /// <param name="pageIndex"></param>
+        /// <param name="renderRect"></param>
+        /// <param name="currentZoom"></param>
+        /// <param name="renderAnnot"></param>
+        /// <param name="renderForm"></param>
+        /// <returns></returns>
         public byte[] RenderPDFPageToArray(CPDFDocument document, int pageIndex, Rect renderRect, double currentZoom, bool renderAnnot = false, bool renderForm = false)
         {
             if (renderRect.Width <= 0 || renderRect.Height <= 0 || document == null)
@@ -1115,6 +1193,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 获取页面的矩形
+        /// </summary>
+        /// <param name="document"></param>
+        /// <param name="pageIndex"></param>
+        /// <param name="displayBox"></param>
+        /// <returns></returns>
         private Rect GetPageRect(CPDFDocument document, int pageIndex, CPDFDisplayBox displayBox)
         {
             CPDFPage currentPage = document.PageAtIndex(pageIndex);
@@ -1126,6 +1211,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             return boundRect;
         }
 
+        /// <summary>
+        /// 获取页面的尺寸
+        /// </summary>
+        /// <param name="document"></param>
+        /// <param name="pageIndex"></param>
+        /// <returns></returns>
         private System.Windows.Size GetPageSize(CPDFDocument document, int pageIndex)
         {
             System.Windows.Size pageSize = document.GetPageSize(pageIndex);

+ 91 - 65
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -372,6 +372,32 @@ namespace PDF_Office.ViewModels
         /// </summary>
         private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
 
+        /// <summary>
+        /// 注释-链接,提示语
+        /// </summary>
+        private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
+
+        public Visibility LinkAnnotTipVisibility
+        {
+            get { return linkAnnotTipVisibility; }
+            set
+            {
+                SetProperty(ref linkAnnotTipVisibility, value);
+            }
+        }
+
+        private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
+
+        public string LinkAnnotTipText
+        {
+            get { return linkAnnotTipText; }
+            set
+            {
+                SetProperty(ref linkAnnotTipText, value);
+            }
+        }
+
+
         #endregion 属性、变量
 
         #region 命令
@@ -744,19 +770,19 @@ namespace PDF_Office.ViewModels
         {
             //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
             System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
-            {
-                NavigationParameters parameters = new NavigationParameters();
-                parameters.Add(ParameterNames.PDFViewer, PDFViewer);
-                parameters.Add(ParameterNames.ViewContentViewModel, this);
-
-                region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
-                region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
-                region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
-
-                //TODO 根据上一次关闭记录的菜单,选中TabItem
-                EnterSelectedBar("TabItemAnnotation");
-            }
-            ));
+                  {
+                      NavigationParameters parameters = new NavigationParameters();
+                      parameters.Add(ParameterNames.PDFViewer, PDFViewer);
+                      parameters.Add(ParameterNames.ViewContentViewModel, this);
+
+                      region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
+                      region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
+                      region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
+
+                      //TODO 根据上一次关闭记录的菜单,选中TabItem
+                      EnterSelectedBar("TabItemAnnotation");
+                  }
+                  ));
         }
 
         /// <summary>
@@ -767,15 +793,15 @@ namespace PDF_Office.ViewModels
         public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
         {
             System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
-            {
-                NavigationParameters parameters = new NavigationParameters();
-                //传其他参数:文档类,空注释面板;
-                parameters.Add(ParameterNames.PDFViewer, PDFViewer);
-                parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
-
-                region.RequestNavigate(PropertyRegionName, Content, parameters);
-            }
-         ));
+                      {
+                          NavigationParameters parameters = new NavigationParameters();
+                          //传其他参数:文档类,空注释面板;
+                          parameters.Add(ParameterNames.PDFViewer, PDFViewer);
+                          parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
+                          parameters.Add(ParameterNames.ViewContentViewModel, this);
+                          region.RequestNavigate(PropertyRegionName, Content, parameters);
+                      }
+                      ));
         }
 
         /// <summary>
@@ -840,48 +866,48 @@ namespace PDF_Office.ViewModels
                 {
                     PDFViewer.UndoManager.CanSave = false;
                     App.Current.Dispatcher.Invoke(() =>
-                    {
-                        //TODO:更新缩略图
-                        //OpenFileInfo info = SettingHelper.GetFileInfo(PdfViewer.Document.FilePath);
-                        //try
-                        //{
-                        //    if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PdfViewer.Document.IsEncrypted)//加密的文档不获取缩略图
-                        //    {
-                        //        var size = PdfViewer.Document.GetPageSize(0);
-                        //        System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PdfViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
-                        //        string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
-                        //        if (File.Exists(folderPath))
-                        //            File.Delete(folderPath);
-                        //        DirectoryInfo folder = new DirectoryInfo(folderPath);
-                        //        if (!folder.Exists)
-                        //            folder.Create();
-                        //        string imagePath = info.ThumbImgPath;
-                        //        if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
-                        //        {
-                        //            string imageName = Guid.NewGuid().ToString();
-                        //            imagePath = System.IO.Path.Combine(folderPath, imageName);
-                        //            using (FileStream stream = new FileStream(imagePath, FileMode.Create))
-                        //            {
-                        //                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
-                        //            }
-                        //        }
-                        //        else
-                        //        {
-                        //            using (FileStream stream = new FileStream(imagePath, FileMode.Open))
-                        //            {
-                        //                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
-                        //            }
-                        //        }
-                        //        info.ThumbImgPath = imagePath;
-                        //        SettingHelper.SetFileInfo(info);
-                        //    }
-                        //}
-                        //catch
-                        //{
-                        //    info.ThumbImgPath = null;
-                        //    SettingHelper.SetFileInfo(info);
-                        //}
-                    });
+                                  {
+                                      //TODO:更新缩略图
+                                      //OpenFileInfo info = SettingHelper.GetFileInfo(PdfViewer.Document.FilePath);
+                                      //try
+                                      //{
+                                      //    if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PdfViewer.Document.IsEncrypted)//加密的文档不获取缩略图
+                                      //    {
+                                      //        var size = PdfViewer.Document.GetPageSize(0);
+                                      //        System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PdfViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
+                                      //        string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
+                                      //        if (File.Exists(folderPath))
+                                      //            File.Delete(folderPath);
+                                      //        DirectoryInfo folder = new DirectoryInfo(folderPath);
+                                      //        if (!folder.Exists)
+                                      //            folder.Create();
+                                      //        string imagePath = info.ThumbImgPath;
+                                      //        if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
+                                      //        {
+                                      //            string imageName = Guid.NewGuid().ToString();
+                                      //            imagePath = System.IO.Path.Combine(folderPath, imageName);
+                                      //            using (FileStream stream = new FileStream(imagePath, FileMode.Create))
+                                      //            {
+                                      //                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
+                                      //            }
+                                      //        }
+                                      //        else
+                                      //        {
+                                      //            using (FileStream stream = new FileStream(imagePath, FileMode.Open))
+                                      //            {
+                                      //                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
+                                      //            }
+                                      //        }
+                                      //        info.ThumbImgPath = imagePath;
+                                      //        SettingHelper.SetFileInfo(info);
+                                      //    }
+                                      //}
+                                      //catch
+                                      //{
+                                      //    info.ThumbImgPath = null;
+                                      //    SettingHelper.SetFileInfo(info);
+                                      //}
+                                  });
                 }
                 else
                 {
@@ -926,7 +952,7 @@ namespace PDF_Office.ViewModels
                         //提示文件被其他软件占用 无法保存
                         //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
                     }
-                      ;
+                ;
                 }
                 return result;
             }

+ 2 - 2
PDF Office/Views/BOTA/AnnotationListItem.xaml.cs

@@ -210,11 +210,11 @@ namespace PDF_Office.Views.BOTA
                         {
                             if (linkAnnotArgs.DestIndex != -1)
                             {
-                                TxbContext.Text = string.Format($"To Page {linkAnnotArgs.DestIndex}");
+                                TxbContext.Text = string.Format($"To Page {linkAnnotArgs.DestIndex + 1}");
                             }
                             else
                             {
-                                TxbContext.Text = string.Format($"To Page {linkAnnotArgs.URI}");
+                                TxbContext.Text = string.Format($"{linkAnnotArgs.URI}");
                             }
                         }
                     }

File diff suppressed because it is too large
+ 18 - 44
PDF Office/Views/Dialog/BOTA/ScreenAnnotationDialog.xaml


+ 14 - 13
PDF Office/Views/ViewContent.xaml

@@ -287,29 +287,30 @@
                 Grid.Column="2"
                 HorizontalAlignment="Stretch"
                 prism:RegionManager.RegionName="{Binding ViwerRegionName}" />
-            <ScrollViewer
-                Name="Scroller"
-                Grid.Column="4"
-                Focusable="False"
-                VerticalScrollBarVisibility="Auto">
-                <ContentControl Height="{Binding ElementName=Scroller, Path=ViewportHeight}" prism:RegionManager.RegionName="{Binding PropertyRegionName}" />
-            </ScrollViewer>
             <Border
-                Name="ViewContentTipPanel"
+                Name="LinkAnnotTipPanel"
                 Grid.Column="2"
-                Width="{Binding ElementName=PDFViewerContent, Path=Width}"
-                HorizontalAlignment="Stretch"
+                Width="{Binding ElementName=PDFViewerContent, Path=Width,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
+                Margin="0,0,18,0"
                 VerticalAlignment="Top"
                 Background=" #BDDFFD"
-                Visibility="Collapsed">
+                Visibility="{Binding LinkAnnotTipVisibility}">
                 <TextBlock
                     x:Name="DrawTipsText"
-                    Margin="12,4"
+                    Margin="12"
                     Padding="4,2,4,2"
                     FontSize="14"
                     Foreground="#252629"
-                    Text="Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range" />
+                    Text="{Binding LinkAnnotTipText}" />
             </Border>
+
+            <ScrollViewer
+                Name="Scroller"
+                Grid.Column="4"
+                Focusable="False"
+                VerticalScrollBarVisibility="Auto">
+                <ContentControl Height="{Binding ElementName=Scroller, Path=ViewportHeight}" prism:RegionManager.RegionName="{Binding PropertyRegionName}" />
+            </ScrollViewer>
         </Grid>
 
         <!--  用于显示页面编辑、水印、背景、标记密文等功能的区域  -->