瀏覽代碼

属性面板- 调整数据绑定逻辑

chenrongqian 2 年之前
父節點
當前提交
2c6aac1598

+ 47 - 1
PDF Office/DataConvert/PropertyPanelVisible.cs

@@ -1,4 +1,5 @@
-using System;
+using ComPDFKitViewer.AnnotEvent;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
@@ -74,4 +75,49 @@ namespace PDF_Office.DataConvert
             throw new NotImplementedException();
         }
     }
+
+
+    public class AnnotArgsTypeConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value is AnnotArgsType)
+            {
+                if (parameter is string)
+                {
+                    var args = (AnnotArgsType)value;
+                    if ((string)parameter == "AnnotHighlight" && args == AnnotArgsType.AnnotHighlight)
+                    {
+                        return Visibility.Visible;
+                    }
+
+                    if ((string)parameter == "AnnotUnderline" && args == AnnotArgsType.AnnotUnderline)
+                    {
+                        return Visibility.Visible;
+                    }
+
+                    if ((string)parameter == "AnnotSquiggly" && args == AnnotArgsType.AnnotSquiggly)
+                    {
+                        return Visibility.Visible;
+                    }
+
+                    if ((string)parameter == "AnnotStrikeout" && args == AnnotArgsType.AnnotStrikeout)
+                    {
+                        return Visibility.Visible;
+                    }
+
+                    if ((string)parameter == "AnnotSticky" && args == AnnotArgsType.AnnotSticky)
+                    {
+                        return Visibility.Visible;
+                    }
+                }
+            }
+            return Visibility.Collapsed;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
 }

+ 6 - 6
PDF Office/Helper/SettingHelper.cs

@@ -159,12 +159,12 @@ namespace PDF_Office.Helper
 
         public static void SetAnnotDefaultProperty(DefaultAnnotProperty annotProperty)
         {
-            //if (Settings.Default.DefautAnnotProperties == null)
-            //{
-            //    Settings.Default.DefautAnnotProperties = new DefaultAnnotProperties();
-            //}
-            //Settings.Default.DefautAnnotProperties.SetAnnotProperty(annotProperty);
-            //Settings.Default.Save();
+            if (Settings.Default.DefautAnnotProperties == null)
+            {
+                Settings.Default.DefautAnnotProperties = new DefaultAnnotProperties();
+            }
+            Settings.Default.DefautAnnotProperties.SetAnnotProperty(annotProperty);
+            Settings.Default.Save();
         }
         private static string KeyAlaphabet = "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
         public static char NumberToChar(int num)

+ 16 - 19
PDF Office/ViewModels/PropertyPanel/AnnotPanel/TextAnnotPropertyViewModel.cs

@@ -14,16 +14,23 @@ using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 {
+    
     public class TextAnnotPropertyViewModel:BindableBase, INavigationAware
     {
+      //  private ComPDFKitViewer.PdfViewer.CPDFViewer PDFViewer;
+        private AnnotHandlerEventArgs Annot;
+        private AnnotPropertyPanel PropertyPanel;
 
         #region 属性
 
         private double annotOpacity;
         public double AnnotOpacity
         {
-            get { return annotOpacity; }
-            set { SetProperty(ref annotOpacity, value); SampleTextBg.Opacity = annotOpacity; SetAnnotProperty();
+            get {return annotOpacity;}
+            set 
+            { 
+                SetProperty(ref annotOpacity, value);
+                SampleTextBg.Opacity = annotOpacity;
                 Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
                 changeData[AnnotType] = annotOpacity;
                 PropertyPanel.DataChangedInvoke(this, changeData);
@@ -163,14 +170,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         }
 
 
-        private ComPDFKitViewer.PdfViewer.CPDFViewer PDFViewer;
-        private AnnotHandlerEventArgs Annot;
-        private AnnotPropertyPanel PropertyPanel;
+       
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
 
             navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
-            navigationContext.Parameters.TryGetValue<ComPDFKitViewer.PdfViewer.CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+          //  navigationContext.Parameters.TryGetValue<ComPDFKitViewer.PdfViewer.CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             if(PropertyPanel != null)
             {
                 Annot = PropertyPanel.annot;
@@ -206,25 +211,19 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                             var Underline = Annot as TextUnderlineAnnotArgs;
                             AnnotOpacity = Underline.Transparency;
                             AnnotType = Underline.EventType;
+                            SampleTextBg = new SolidColorBrush(Underline.Color);
                         }
                         break;
 
                     case AnnotArgsType.AnnotSquiggly:
                         {
-                            var Underline = Annot as TextSquigglyAnnotArgs;
-                            AnnotOpacity = Underline.Transparency;
-                            AnnotType = Underline.EventType;
+                            var Squiggly = Annot as TextSquigglyAnnotArgs;
+                            AnnotOpacity = Squiggly.Transparency;
+                            AnnotType = Squiggly.EventType;
+                            SampleTextBg = new SolidColorBrush(Squiggly.Color);
                         }
                         break;
 
-                    //case AnnotArgsType.AnnotStrikeout:
-                    //    {
-                    //        var Underline = Annot as TextStrikeoutAnnotArgs;
-                    //        AnnotOpacity = Underline.Transparency;
-                    //        AnnotType = Underline.EventType;
-                    //    }
-                    //    break;
-
                 }
             }
         }
@@ -280,7 +279,5 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-
-
     }
 }

+ 4 - 89
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -24,107 +24,22 @@ using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.Tools
 {
-    public class AnnotPropertyPanel
-    {
-        public AnnotHandlerEventArgs annot;
-        public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
-        public event EventHandler<object> DefaultStored;
-        public AnnotPropertyPanel()
-        {
-        }
-
-        public void  DataChangedInvoke(object sender,Dictionary<AnnotArgsType, object> keyValues)
-        {
-            DataChanged?.Invoke(sender,keyValues);
-        }
 
-
-    }
-    public class AnnotToolContentViewModel : BindableBase, INavigationAware
+    public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
     {
+       
 
 
-        #region 注释工具
-
-        private Brush highLightColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush HighLightColor
-        {
-            get { return highLightColor; }
-            set { SetProperty(ref highLightColor, value); }
-        }
-
-
-        private double highLightOpacity = 1;
-        public double HighLightOpacity
-        {
-            get { return highLightOpacity; }
-            set { SetProperty(ref highLightOpacity, value); }
-        }
-
-
-        private Brush underLine = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush UnderLineColor
-        {
-            get { return underLine; }
-            set { SetProperty(ref underLine, value); }
-        }
-
-
-        private double underLineOpacity = 1;
-        public double UnderLineOpacity
-        {
-            get { return underLineOpacity; }
-            set { SetProperty(ref underLineOpacity, value); }
-        }
-
-
-
-        private Brush squigglyColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush SquigglyColor
-        {
-            get { return squigglyColor; }
-            set { SetProperty(ref squigglyColor, value); }
-        }
-
-
-        private double squigglyOpacity = 1;
-        public double SquigglyOpacity
-        {
-            get { return squigglyOpacity; }
-            set { SetProperty(ref squigglyOpacity, value); }
-        }
-
-
-
-        private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush StrikeoutColor
-        {
-            get { return strikeoutColor; }
-            set { SetProperty(ref strikeoutColor, value); }
-        }
-
-
-        private double strikeoutOpacity = 1;
-        public double StrikeoutOpacity
-        {
-            get { return strikeoutOpacity; }
-            set { SetProperty(ref strikeoutOpacity, value); }
-        }
-
-        #endregion
-
-        private CPDFViewer PDFViewer;
-        private ViewContentViewModel viewContentViewModel;
-        public DelegateCommand<CustomIconToggleBtn> MyToolsCommand { get; set; }
-
         public AnnotToolContentViewModel(IRegionManager regionManager)
         {
             region = regionManager;
 
             MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
             PropertyRegionName = Guid.NewGuid().ToString();
+            InitDefaultValue();
         }
 
+
         private Dictionary<string, bool> ToolExpandDict = new Dictionary<string, bool>();
         public void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
         {

+ 5 - 3
PDF Office/Views/PropertyPanel/AnnotPanel/TextAnnotProperty.xaml

@@ -10,6 +10,7 @@
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:AnnotPanel="clr-namespace:PDF_Office.ViewModels.PropertyPanel.AnnotPanel"
              d:DataContext="{d:DesignInstance Type=AnnotPanel:TextAnnotPropertyViewModel}"
+             xmlns:Convert="clr-namespace:PDF_Office.DataConvert"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <UserControl.Resources>
@@ -17,6 +18,7 @@
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="../../../Styles/SliderStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
+            <Convert:AnnotArgsTypeConverter x:Key="AnnotArgsTypeConverter"/>
         </ResourceDictionary>
     </UserControl.Resources>
     <Grid  VerticalAlignment="Stretch" Background="Wheat">
@@ -30,17 +32,17 @@
                              Background="{Binding SampleTextBg}" 
                                >
                     </TextBlock>
-                    <Path Name="UnderlinePath" HorizontalAlignment="Center" StrokeThickness="2" Margin="0,51,0,0" Visibility="Collapsed">
+                    <Path Name="UnderlinePath" HorizontalAlignment="Center" StrokeThickness="2" Margin="0,51,0,0" Visibility="{Binding AnnotType,Converter={StaticResource AnnotArgsTypeConverter},ConverterParameter=AnnotUnderline}">
                         <Path.Data>
                             <LineGeometry StartPoint="0,0" EndPoint="62,0"></LineGeometry>
                         </Path.Data>
                     </Path>
-                    <Path Name="StrikeoutPath" HorizontalAlignment="Center" StrokeThickness="2" Margin="0,40,0,0" Visibility="Collapsed">
+                    <Path Name="StrikeoutPath" HorizontalAlignment="Center" StrokeThickness="2" Margin="0,40,0,0" Visibility="{Binding AnnotType,Converter={StaticResource AnnotArgsTypeConverter},ConverterParameter=AnnotStrikeout}">
                         <Path.Data>
                             <LineGeometry StartPoint="0,0" EndPoint="62,0"></LineGeometry>
                         </Path.Data>
                     </Path>
-                    <Path Name="SquigglyPath"  HorizontalAlignment="Center" StrokeThickness="2" Margin="0,51,0,0" Visibility="Collapsed">
+                    <Path Name="SquigglyPath"  HorizontalAlignment="Center" StrokeThickness="2" Margin="0,51,0,0" Visibility="{Binding AnnotType,Converter={StaticResource AnnotArgsTypeConverter},ConverterParameter=AnnotSquiggly}">
 
                     </Path>