Browse Source

属性面板 - 形状注释、文本注释

chenrongqian 2 years ago
parent
commit
8f848ed780

+ 25 - 0
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -99,6 +99,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
         public DelegateCommand<object> FontStyleChangedCommand { get; set; }
         public DelegateCommand<object> FontSizeChangedCommand { get; set; }
+        public DelegateCommand<object> TextAlignChecked { get; set; }
+        
 
         public event EventHandler<object> LoadPropertyHandler;
         public FreetextAnnotPropertyViewModel()
@@ -108,6 +110,29 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged_Command);
             FontStyleChangedCommand = new DelegateCommand<object>(FontStyleChanged_Command);
             FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged_Command);
+            TextAlignChecked = new DelegateCommand<object>(TextAlign_Checked);
+        }
+
+        private void TextAlign_Checked(object obj)
+        {
+            if (obj != null && (string)obj != null)
+            {
+                var tag = (string)obj;
+                switch (tag)
+                {
+                    case "AlignLeft":
+                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
+                        break;
+                    case "AlignCenter":
+                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
+                        break;
+                    case "AlignRight":
+                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
+                        break;
+                }
+                AnnotEvent?.UpdateAnnot();
+
+            }
         }
 
         private void FontSizeChanged_Command(object obj)

+ 250 - 9
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SharpsAnnotPropertyViewModel.cs

@@ -1,5 +1,7 @@
-using ComPDFKitViewer;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKitViewer;
 using ComPDFKitViewer.AnnotEvent;
+using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.ViewModels.Tools;
 using Prism.Commands;
@@ -7,15 +9,49 @@ using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
 using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 {
+
+    public class DashStyleConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value is DashStyle)
+            {
+                var dash = value as DashStyle;
+                if (dash.Dashes.Count == 0 || dash.Dashes[0] == 0)
+                {
+                   return DashStyles.Solid.Dashes; 
+                }
+                else
+                {
+                    DashStyle dashx = new DashStyle();
+                    dashx.Dashes.Add(1);
+                    dashx.Dashes.Add(1);
+                    return dashx.Dashes;
+                }
+            }
+            return value;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
     public class SharpsAnnotPropertyViewModel : BindableBase, INavigationAware
     {
+        #region 属性
+
         private AnnotArgsType annotType;
         public AnnotArgsType AnnotType
         {
@@ -53,14 +89,14 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public Brush FillColor
         {
             get { return fillColor; }
-            set { 
+            set
+            {
                 SetProperty(ref fillColor, value);
                 AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, (fillColor as SolidColorBrush).Color);
                 AnnotEvent?.UpdateAnnot();
             }
         }
 
-
         private double borderOpacity = 1;
         public double BorderOpacity
         {
@@ -88,11 +124,50 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             set
             {
                 SetProperty(ref lineWidth, value);
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
+
+                if (annotType == AnnotArgsType.AnnotLine)
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
+                else
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
+
+                AnnotEvent?.UpdateAnnot();
+            }
+        }
+
+        private Geometry dataPath = null;
+        public Geometry DataPath
+        {
+            get { return dataPath; }
+            set
+            {
+                SetProperty(ref dataPath, value);
+            }
+        }
+
+        private DashStyle dash = new DashStyle();
+        public DashStyle Dash
+        {
+            get { return dash; }
+            set
+            {
+                SetProperty(ref dash, value);
+                if(dash.Dashes[0] == 0)
+                {
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
+                }
+                else
+                {
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dash);
+                }
+                
                 AnnotEvent?.UpdateAnnot();
             }
         }
 
+        
+
+        #endregion
+
         public DelegateCommand<object> SelectedThickCommand { get; set; }
         public DelegateCommand<object> SelectedColorCommand { get; set; }
 
@@ -100,6 +175,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand<object> SelectedFillColorCommand { get; set; }
 
         public DelegateCommand<object> LineStyleCommand { get; set; }
+
+        public DelegateCommand<object> SharpsTypeCommand { get; set; }
+        public DelegateCommand<object> ThicknessChangedCommand { get; set; }
+        
+        public event EventHandler<object> LoadPropertyHandler;
         public SharpsAnnotPropertyViewModel()
         {
             SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
@@ -107,6 +187,85 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity_Command);
             SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
             LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
+            SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
+            ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
+
+        }
+
+        private void ThicknessChanged_Command(object obj)
+        {
+            if (obj != null)
+            {
+                var item = (ComboBoxItem)obj;
+                var content = (string)item.Content;
+                if (content != null)
+                {
+                    var intData = int.Parse(content);
+                    LineWidth = intData;
+                }
+            }
+        }
+
+        private void SharpsType_Command(object obj)
+        {
+            if(obj != null)
+            {
+                var tag = (string)obj;
+                SharpsType(tag);
+            }
+        }
+
+        private void SharpsType(string tag,bool isFromToolsBtn = false)
+        {
+            Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
+            switch (tag)
+            {
+                case "Rect":
+                    RectangleGeometry rectPath = new RectangleGeometry();
+                    rectPath.Rect = new Rect(0, 5, 28, 22);
+                    DataPath = rectPath;
+                    changeData[AnnotArgsType.AnnotSquare] = tag;
+                    break;
+
+                case "Circle":
+                    EllipseGeometry circlePath = new EllipseGeometry();
+                    circlePath.RadiusX = 14;
+                    circlePath.RadiusY = 14;
+                    circlePath.Center = new Point(14, 14);
+                    DataPath = circlePath;
+                    changeData[AnnotArgsType.AnnotCircle] = tag;
+                    break;
+
+                case "Arrow":
+                    {
+                   
+                        ArrowHelper arrowLine = new ArrowHelper();
+                        arrowLine.ArrowLength = 8;
+                        arrowLine.LineStart = new Point(8, 24);
+                        arrowLine.LineEnd = new Point(24, 8);
+                        arrowLine.StartSharp = C_LINE_TYPE.LINETYPE_NONE;
+                        arrowLine.EndSharp = C_LINE_TYPE.LINETYPE_ARROW;
+                        DataPath = arrowLine.BuildArrowBody();
+                        changeData[AnnotArgsType.AnnotLine] = tag;
+                        //  changeData[AnnotArgsType.AnnotLine] = tag;
+                    }
+
+                    break;
+
+                case "Line":
+                    {
+                        ArrowHelper arrowLine = new ArrowHelper();
+                        arrowLine.LineStart = new Point(0, 32);
+                        arrowLine.LineEnd = new Point(32, 0);
+                        DataPath = arrowLine.BuildArrowBody();
+                        changeData[AnnotArgsType.AnnotLine] = tag;
+                    }
+                   
+                    break;
+            }
+
+            if (isFromToolsBtn == false)
+                PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
 
         }
 
@@ -117,11 +276,18 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var tag = obj as string;
                 if(tag == "Solid")
                 {
-
+                    DashStyle dashAnnot = new DashStyle();
+                    dashAnnot.Dashes.Add(0);
+                    dashAnnot.Dashes.Add(0);
+                    Dash = dashAnnot;
                 }
                 else
                 {
-
+                  
+                    DashStyle dashAnnot = new DashStyle();
+                    dashAnnot.Dashes.Add(1);
+                    dashAnnot.Dashes.Add(1);
+                    Dash = dashAnnot;
                 }
             }
         }
@@ -158,6 +324,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
                 PropertyPanel.DataChangedInvoke(this, changeData);
             }
+
         }
 
         private void SelectedColor_Command(object obj)
@@ -175,12 +342,22 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     changeData[AnnotArgsType.AnnotFreehand] = obj;
                     PropertyPanel.DataChangedInvoke(this, changeData);
                 }
+
             }
+
         }
 
         private void SelectedThick_Command(object obj)
         {
-          
+            if (obj is double)
+            {
+                var tran = (double)obj;
+                BorderOpacity = tran;
+                SelectColor.Opacity = tran;
+
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
+                AnnotEvent?.UpdateAnnot();
+            }
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)
@@ -203,14 +380,18 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     AnnotTypeTitle = "矩形";
                     break;
                 case AnnotArgsType.AnnotLine:
-                    AnnotTypeTitle = "线";
+                
                   var annotLine =  Annot as LineAnnotArgs;
                     if (annotLine != null)
                     {
-                        
+                        if (annotLine.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annotLine.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
+                            AnnotTypeTitle = "箭头";
+                        else
+                            AnnotTypeTitle = "线";
                     }
                     break;
             }
+
         }
 
         public AnnotAttribEvent AnnotEvent { get; set; }
@@ -224,8 +405,68 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 AnnotEvent = PropertyPanel.AnnotEvent;
                 AnnotType = PropertyPanel.annot.EventType;
                 Annot = PropertyPanel.annot;
+                GetAnnotProperty();
+                LoadPropertyHandler?.Invoke(null, Annot);
             }
+
         }
 
+        private void GetAnnotProperty()
+        {
+            if (Annot != null)
+            {
+                switch (Annot.EventType)
+                {
+                    case AnnotArgsType.AnnotSquare:
+                        if (Annot is SquareAnnotArgs)
+                        {
+                            var Square = Annot as SquareAnnotArgs;
+                            SelectColor = new SolidColorBrush(Square.LineColor);
+                            FillColor = new SolidColorBrush(Square.BgColor);
+                            BorderOpacity = Square.Transparency;
+                            FillOpacity = Square.Transparency;
+                            LineWidth = Square.LineWidth;
+                            SharpsType("Rect",true);
+                            
+                        }
+                        break;
+
+                    case AnnotArgsType.AnnotCircle:
+                        if (Annot is CircleAnnotArgs)
+                        {
+                            var Circle = Annot as CircleAnnotArgs;
+                            SelectColor = new SolidColorBrush(Circle.LineColor);
+                            FillColor = new SolidColorBrush(Circle.BgColor);
+                            BorderOpacity = Circle.Transparency;
+                            FillOpacity = Circle.Transparency;
+                            LineWidth = Circle.LineWidth;
+                            SharpsType("Circle", true);
+                        }
+                        break;
+
+                    case AnnotArgsType.AnnotLine:
+                        if (Annot is LineAnnotArgs)
+                        {
+                            var line = Annot as LineAnnotArgs;
+                            SelectColor = new SolidColorBrush(line.LineColor);
+                            FillColor = new SolidColorBrush(line.LineColor);
+                            BorderOpacity = line.Transparency;
+                            FillOpacity = line.Transparency;
+                            LineWidth = line.LineWidth;
+
+                            if (line.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && line.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
+                                SharpsType("Arrow", true);
+                            else
+                                SharpsType("Line", true);
+                        }
+
+                        break;
+                }
+
+            }
+
+        }
+
+
     }
 }

+ 22 - 10
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -25,6 +25,7 @@ namespace PDF_Office.ViewModels.Tools
         {
             propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
             propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
+            propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
         }
 
         private void InitDefaultValue()
@@ -381,6 +382,7 @@ namespace PDF_Office.ViewModels.Tools
             if(selectedsquareArgs == null)
             {
                 squareArgs = new SquareAnnotArgs();
+
                 squareArgs.LineColor = Colors.Red;
                 squareArgs.BgColor = Colors.Transparent;
                 squareArgs.LineWidth = 1;
@@ -388,6 +390,7 @@ namespace PDF_Office.ViewModels.Tools
                 squareArgs.LineDash = DashStyles.Solid;
                 squareArgs.Content = string.Empty;
                 DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
+
                 if (annotProperty != null)
                 {
                     squareArgs.LineColor = annotProperty.BorderColor;
@@ -479,24 +482,33 @@ namespace PDF_Office.ViewModels.Tools
             return circleAnnotArgs;
         }
 
-        private AnnotHandlerEventArgs GetArrowLine(string TagStr)
+        private AnnotHandlerEventArgs GetArrowLine(string TagStr,LineAnnotArgs selectedLineAnnotArgs = null)
         {
             Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
             LineAnnotArgs lineArgs = new LineAnnotArgs();
-            lineArgs.LineColor = Colors.Red;
-            lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
-            if (TagStr == "Line")
+
+            if(selectedLineAnnotArgs == null)
             {
-                lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
+
+                lineArgs.LineColor = Colors.Red;
+                lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
+                if (TagStr == "Line")
+                {
+                    lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
+                }
+                else
+                {
+                    lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
+                }
+                lineArgs.LineDash = DashStyles.Solid;
+                lineArgs.LineWidth = 1;
+                lineArgs.Transparency = 1;
+                lineArgs.Content = string.Empty;
             }
             else
             {
-                lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
+                lineArgs = selectedLineAnnotArgs;
             }
-            lineArgs.LineDash = DashStyles.Solid;
-            lineArgs.LineWidth = 1;
-            lineArgs.Transparency = 1;
-            lineArgs.Content = string.Empty;
 
             DefaultAnnotProperty annotProperty = null;
             if (TagStr == "Line")

+ 6 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -20,6 +20,7 @@ namespace PDF_Office.ViewModels.Tools
         public AnnotAttribEvent AnnotEvent { get; set; }
         public AnnotHandlerEventArgs annot;
         public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
+        public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
         public event EventHandler<object> DefaultStored;
         public AnnotPropertyPanel(){ }
 
@@ -27,6 +28,11 @@ namespace PDF_Office.ViewModels.Tools
         {
             DataChanged?.Invoke(sender, keyValues);
         }
+
+        public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
+        {
+            AnnotTypeChanged?.Invoke(sender, keyValues);
+        }
     }
 
     public sealed partial class AnnotToolContentViewModel

+ 62 - 1
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -135,6 +135,42 @@ namespace PDF_Office.ViewModels.Tools
            
         }
 
+        private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
+        {
+            if (e != null)
+            {
+                AnnotHandlerEventArgs annotArgs = null;
+                foreach (AnnotArgsType argsType in e.Keys)
+                {
+                    switch (argsType)
+                    {
+                        case AnnotArgsType.AnnotSquare:
+                            annotArgs = GetRect();
+                            break;
+
+                        case AnnotArgsType.AnnotCircle:
+                            annotArgs = GetCircle();
+                            break;
+
+                        case AnnotArgsType.AnnotLine:
+                            var LineTag = e[argsType] as string;
+                            annotArgs = GetArrowLine(LineTag);
+                            break;
+
+                    }
+                    if (annotArgs != null)
+                    {
+                        annotArgs.Author = Settings.Default.AppProperties.Description.Author;
+                        PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                        PDFViewer.SetToolParam(annotArgs);
+
+                    }
+                    ShowPropertyPanel();
+                }
+            }
+        }
+        
+
         private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
         {
             if (e != null)
@@ -366,11 +402,36 @@ namespace PDF_Office.ViewModels.Tools
                             GetCircle(annot as CircleAnnotArgs);
                             break;
                         case AnnotArgsType.AnnotLine:
-                          
+                            bool isLine = true;
+                            if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
+                            {
+                                if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
+                                {
+                                    isLine = false;
+                                }
+                            }
+                            if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
+                            {
+                                if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
+                                {
+                                    isLine = false;
+                                }
+                            }
+
+                            if (isLine)
+                                GetArrowLine("Line", annot as LineAnnotArgs);
+                            else
+                                GetArrowLine("Arrow", annot as LineAnnotArgs);
+
                             break;
                     }
                 }
             }
+            else
+            {
+               // PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                //  viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+            }
            
         }
 

+ 16 - 1
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PDF_Office.Views.PropertyPanel.AnnotPanel"
              xmlns:CommonControls="clr-namespace:PDF_Office.Views.PropertyPanel.AnnotPanel.CommonControls"
-              xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:prism="http://prismlibrary.com/"             
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:Convert="clr-namespace:PDF_Office.DataConvert"
@@ -245,18 +245,33 @@
                         <ToggleButton Name="TextAlignLeftBtn" Tag="AlignLeft" Background="Transparent" BorderThickness="0" Click="BtnTextAlign_Click">
                             <Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#000000" Data="M10,11 L10,12 L0,12 L0,11 L10,11 Z M16,7 L16,8 L0,8 L0,7 L16,7 Z M13,3 L13,4 L0,4 L0,3 L13,3 Z">
                             </Path>
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Checked">
+                                    <i:InvokeCommandAction Command="{Binding TextAlignChecked}" CommandParameter="{Binding ElementName=TextAlignLeftBtn,Path=Tag}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
                         </ToggleButton>
                         <Line HorizontalAlignment="Left" Style="{StaticResource line1Style}" VerticalAlignment="Center" Grid.Column="1" X1="0" Y1="0" X2="0" Y2="16" StrokeThickness="1" Stroke="#33000000"></Line>
 
                         <ToggleButton Name="TextAlignCenterBtn" Tag="AlignCenter" Grid.Column="1" Background="Transparent"  BorderThickness="0"  Click="BtnTextAlign_Click">
                             <Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#000000" Data="M16,11 L16,12 L0,12 L0,11 L16,11 Z M13,7 L13,8 L3,8 L3,7 L13,7 Z M16,3 L16,4 L0,4 L0,3 L16,3 Z">
                             </Path>
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Checked">
+                                    <i:InvokeCommandAction Command="{Binding TextAlignChecked}" CommandParameter="{Binding ElementName=TextAlignCenterBtn,Path=Tag}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
                         </ToggleButton>
                         <Line HorizontalAlignment="Left" Style="{StaticResource line2Style}" VerticalAlignment="Center" Grid.Column="2" X1="0" Y1="0" X2="0" Y2="16" StrokeThickness="1" Stroke="#33000000"></Line>
 
                         <ToggleButton Name="TextAlignRightBtn" Tag="AlignRight" Grid.Column="2" Background="Transparent"  BorderThickness="0"  Click="BtnTextAlign_Click">
                             <Path HorizontalAlignment="Center" VerticalAlignment="Center"  Fill="#000000" Data="M16,11 L16,12 L6.00061035,12 L6.00061035,11 L16,11 Z M16,7 L16,8 L0.0009765625,8 L0.0009765625,7 L16,7 Z M16,3 L16,4 L3.00079346,4 L3.00079346,3 L16,3 Z">
                             </Path>
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Checked">
+                                    <i:InvokeCommandAction Command="{Binding TextAlignChecked}" CommandParameter="{Binding ElementName=TextAlignRightBtn,Path=Tag}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
                         </ToggleButton>
                     </Grid>
                 </Border>

+ 32 - 11
PDF Office/Views/PropertyPanel/AnnotPanel/SharpsAnnotProperty.xaml

@@ -4,9 +4,13 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PDF_Office.Views.PropertyPanel.AnnotPanel"
-              xmlns:cus="clr-namespace:PDF_Office.CustomControl"
+             xmlns:cus="clr-namespace:PDF_Office.CustomControl"
              xmlns:CommonControls="clr-namespace:PDF_Office.Views.PropertyPanel.AnnotPanel.CommonControls"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:prism="http://prismlibrary.com/"             
+             prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:Convert="clr-namespace:PDF_Office.DataConvert"
+              xmlns:DashConvert="clr-namespace:PDF_Office.ViewModels.PropertyPanel.AnnotPanel"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <UserControl.Resources>
@@ -17,7 +21,8 @@
             </ResourceDictionary.MergedDictionaries>
             <Convert:ColorToBrushConverter x:Key="ColorToBrushConvert"></Convert:ColorToBrushConverter>
             <Convert:CheckToVisibleMutiConvert x:Key="CheckToVisibleMutiConvert"/>
-         
+            <DashConvert:DashStyleConverter x:Key="DashStyleConverter"/>
+
             <Style x:Key="line1Style" TargetType="{x:Type Line}">
                 <Setter Property="Visibility">
                     <Setter.Value>
@@ -56,11 +61,13 @@
             <TextBlock Name="AnnotTypeTitle" Text="{Binding AnnotTypeTitle}" FontFamily="SegoeUI" FontWeight="Bold" FontSize="18" LineHeight="24" HorizontalAlignment="Left" Margin="10,8,0,0" />
             <Border Width="228" Height="100" BorderThickness="1" CornerRadius="2" BorderBrush="#DDDDDD" Background="White" Margin="0,8,0,0">
                 <Grid>
-                    <!--<Path Name="SharpPath" Opacity="{Binding ElementName=OpacitySlider,Path=Value}" StrokeThickness="{Binding ElementName=ThicknessSlider,Path=Value}" 
-                        Stroke="{Binding ElementName=BorderColorPicker,Path=SelectedColor,Converter={StaticResource ColorToBrushConvert}}"
-                        Fill="{Binding ElementName=FillColorPicker,Path=SelectedColor,Converter={StaticResource ColorToBrushConvert}}"
+                    <Path Name="SharpPath" Opacity="{Binding FillOpacity}" StrokeThickness="{Binding LineWidth}"  Data="{Binding DataPath}"
+                        Stroke="{Binding SelectColor}"
+                        Fill="{Binding FillColor}" StrokeStartLineCap="Flat"
+                         StrokeDashArray="{Binding Dash,Converter={StaticResource DashStyleConverter}}"
                         Width="36" Height="36" HorizontalAlignment="Center" VerticalAlignment="Center">
-                    </Path>-->
+                        <!--,Converter={StaticResource ColorToBrushConvert}-->
+                    </Path>
                 </Grid>
             </Border>
 
@@ -75,7 +82,8 @@
                     </Grid.ColumnDefinitions>
 
 
-                    <ToggleButton Name="SharpRectBtn" Tag="Rect" Width="40.5" Background="Transparent" BorderThickness="0" Click="SharpsBtn_Click">
+                    <ToggleButton Name="SharpRectBtn" Tag="Rect" Width="40.5" Background="Transparent" BorderThickness="0" Click="SharpsBtn_Click" 
+                                  Command="{Binding SharpsTypeCommand}" CommandParameter="{Binding ElementName=SharpRectBtn,Path=Tag}">
                         <Rectangle HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" Stroke="#273C62"></Rectangle>
                     </ToggleButton>
 
@@ -83,13 +91,17 @@
 
                     </Line>
 
-                    <ToggleButton Name="SharpCircleBtn" Width="40.5" Tag="Circle" Grid.Column="1" Background="Transparent"  BorderThickness="0"  Margin="0,0,0,0" Click="SharpsBtn_Click">
+                    <ToggleButton Name="SharpCircleBtn" Width="40.5" Tag="Circle" Grid.Column="1" Background="Transparent"  BorderThickness="0"  Margin="0,0,0,0" Click="SharpsBtn_Click"
+                                  Command="{Binding SharpsTypeCommand}" CommandParameter="{Binding ElementName=SharpCircleBtn,Path=Tag}"
+                                  >
                         <Ellipse Width="16" Height="16" Stroke="#273C62" HorizontalAlignment="Center" VerticalAlignment="Center"  ></Ellipse>
                     </ToggleButton>
 
 
                     <Line Name="line2" HorizontalAlignment="Left" Style="{StaticResource line2Style}" VerticalAlignment="Center" Grid.Column="2" X1="0" Y1="0" X2="0" Y2="16" StrokeThickness="1" Stroke="#33000000"></Line>
-                    <ToggleButton Name="SharpArrowBtn" Width="40.5" Tag="Arrow" Grid.Column="2" Background="Transparent"  BorderThickness="0" Click="SharpsBtn_Click">
+                    <ToggleButton Name="SharpArrowBtn" Width="40.5" Tag="Arrow" Grid.Column="2" Background="Transparent"  BorderThickness="0" Click="SharpsBtn_Click"
+                                    Command="{Binding SharpsTypeCommand}" CommandParameter="{Binding ElementName=SharpArrowBtn,Path=Tag}"
+                                  >
                         <Path HorizontalAlignment="Center" VerticalAlignment="Center"  Fill="#273C62" Width="16" Height="16">
                             <Path.Data>
                                 M13.4,2.6 L13.4,8 L12.2,8 L12.1997359,4.648 L2.02426407,14.8242641 L1.17573593,13.9757359 L11.3517359,3.799 L8,3.8 L8,2.6 L13.4,2.6 Z
@@ -98,7 +110,9 @@
                     </ToggleButton>
 
                     <Line x:Name="line3" HorizontalAlignment="Left" Style="{StaticResource line3Style}" VerticalAlignment="Center" Grid.Column="3" X1="0" Y1="0" X2="0" Y2="16" StrokeThickness="1" Stroke="#33000000"></Line>
-                    <ToggleButton Name="SharpLineBtn" Width="40.5" Tag="Line" Grid.Column="3" Background="Transparent"  BorderThickness="0" Click="SharpsBtn_Click">
+                    <ToggleButton Name="SharpLineBtn" Width="40.5" Tag="Line" Grid.Column="3" Background="Transparent"  BorderThickness="0" Click="SharpsBtn_Click"
+                                   Command="{Binding SharpsTypeCommand}" CommandParameter="{Binding ElementName=SharpLineBtn,Path=Tag}"
+                                  >
                         <Polygon Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#273C62">
                             <Polygon.Points>
                                 13.1757359 1.97573593 14.0242641 2.82426407 2.82426407 14.0242641 1.97573593 13.1757359
@@ -152,11 +166,18 @@
                                     <Setter Property="Padding" Value="10 0 0 0"/>
                                 </Style>
                             </ComboBox.ItemContainerStyle>
-                            <ComboBoxItem Content="1" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}"/>
+                            <ComboBoxItem Content="1" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}">
+                                
+                            </ComboBoxItem>
                             <ComboBoxItem Content="3" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}"/>
                             <ComboBoxItem Content="6" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}"/>
                             <ComboBoxItem Content="9" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}"/>
                             <ComboBoxItem Content="12" Height="32" VerticalContentAlignment="Center" Template="{StaticResource comboxitem}"/>
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="SelectionChanged">
+                                    <i:InvokeCommandAction Command="{Binding ThicknessChangedCommand}" CommandParameter="{Binding ElementName=BorderDropBox,Path=SelectedItem}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
                         </ComboBox>
                         <TextBox FontFamily="Segoe UI" FontSize="14" Background="White" Height="20" Margin="10,0,35,0" IsReadOnly="True"
                              BorderThickness="0" VerticalAlignment="Center" TextAlignment="Left" Text="{Binding ElementName=BorderSlider,Path=Value}">

+ 64 - 13
PDF Office/Views/PropertyPanel/AnnotPanel/SharpsAnnotProperty.xaml.cs

@@ -1,4 +1,6 @@
-using PDF_Office.CustomControl;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKitViewer.AnnotEvent;
+using PDF_Office.CustomControl;
 using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
 using System;
 using System.Collections.Generic;
@@ -23,6 +25,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
     /// </summary>
     public partial class SharpsAnnotProperty : UserControl
     {
+        private SharpsAnnotPropertyViewModel ViewModel => DataContext as SharpsAnnotPropertyViewModel;
         public SharpsAnnotProperty()
         {
             InitializeComponent();
@@ -31,41 +34,89 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
 
             cusFillColor.SelectedColorHandler += cusFillColor_SelectedColor;
             layerFill.SelectedValueChanged += layerFill_SelectedValue;
+            ViewModel.LoadPropertyHandler += ViewModel_LoadPropertyHandler;
+        }
+
+        private void ViewModel_LoadPropertyHandler(object sender, object e)
+        {
+            var item = e as AnnotHandlerEventArgs;
+            switch (item.EventType)
+            {
+                case AnnotArgsType.AnnotSquare:
+                    {
+                        var annot = item as SquareAnnotArgs;
+                        if (annot != null)
+                        {
+                            cusColor.SetSelectedColor(annot.LineColor);
+                            cusFillColor.SetSelectedColor(annot.BgColor);
+                            layerFill.SetSliOpacity(annot.Transparency);
+                            SharpsBtn_Click(SharpRectBtn, null);
+                        }
+                        break;
+                    }
+
+                case AnnotArgsType.AnnotCircle:
+                    {
+                        var annot = item as CircleAnnotArgs;
+                        if (annot != null)
+                        {
+                            cusColor.SetSelectedColor(annot.LineColor);
+                            cusFillColor.SetSelectedColor(annot.BgColor);
+                            layerFill.SetSliOpacity(annot.Transparency);
+                            SharpsBtn_Click(SharpCircleBtn, null);
+                        }
+                        break;
+                    }
+
+                case AnnotArgsType.AnnotLine:
+                    {
+                        var annot = item as LineAnnotArgs;
+                        if (annot != null)
+                        {
+                            cusColor.SetSelectedColor(annot.LineColor);
+                            cusFillColor.SetSelectedColor(annot.LineColor);
+                            layerFill.SetSliOpacity(annot.Transparency);
+
+                            if (annot.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
+                                SharpsBtn_Click(SharpArrowBtn, null);
+                            else
+                                SharpsBtn_Click(SharpLineBtn, null);
+
+                        }
+                        break;
+                    }
+            }
         }
 
         private void layerFill_SelectedValue(object sender, double e)
         {
-            var data = this.DataContext as SharpsAnnotPropertyViewModel;
-            if (data != null)
+            if (ViewModel != null)
             {
-                data.SelectedFillOpacityCommand?.Execute(e);
+                ViewModel.SelectedFillOpacityCommand?.Execute(e);
             }
         }
 
         private void cusFillColor_SelectedColor(object sender, Color e)
         {
-            var data = this.DataContext as SharpsAnnotPropertyViewModel;
-            if (data != null)
+            if (ViewModel != null)
             {
-                data.SelectedFillColorCommand?.Execute(e);
+                ViewModel.SelectedFillColorCommand?.Execute(e);
             }
         }
 
         private void layerThick_SelectedValue(object sender, double e)
         {
-            var data = this.DataContext as SharpsAnnotPropertyViewModel;
-            if (data != null)
+            if (ViewModel != null)
             {
-                data.SelectedThickCommand?.Execute(e);
+                ViewModel.SelectedThickCommand?.Execute(e);
             }
         }
 
         private void cusColor_SelectedColor(object sender, Color e)
         {
-            var data = this.DataContext as SharpsAnnotPropertyViewModel;
-            if (data != null)
+            if (ViewModel != null)
             {
-                data.SelectedColorCommand?.Execute(e);
+                ViewModel.SelectedColorCommand?.Execute(e);
             }
         }