Selaa lähdekoodia

Form - 下拉框、勾选框UI绑定

chenrongqian 2 vuotta sitten
vanhempi
commit
570affa825

+ 15 - 7
PDF Office/ViewModels/Form/CheckBoxPropertyViewModel.cs

@@ -1,4 +1,6 @@
-using ComPDFKitViewer.AnnotEvent;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKit.PDFAnnotation.Form;
+using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.Model;
 using Prism.Mvvm;
@@ -47,6 +49,7 @@ namespace PDF_Office.ViewModels.Form
         #region 变量
         private CPDFViewer PDFViewer;
         private WidgetCheckBoxArgs checkBoxArgs;
+        private bool IsCurrentWidget = false;
         #endregion
 
         #region 初始化
@@ -103,15 +106,20 @@ namespace PDF_Office.ViewModels.Form
 
         private void GetWidgeText()
         {
-            PDFViewer.SetMouseMode(MouseModes.FormEditTool);
+           
             if (checkBoxArgs == null)
             {
+                PDFViewer.SetMouseMode(MouseModes.FormEditTool);
                 checkBoxArgs = new WidgetCheckBoxArgs();
-                checkBoxArgs.BgColor = Colors.Transparent;
-                checkBoxArgs.FontColor = Colors.Black;
-                checkBoxArgs.LineWidth = 1;
-                checkBoxArgs.LineColor = Colors.Black;
-                checkBoxArgs.FieldName = "CheckBox1";
+                WidgetCheckBoxArgs args = new WidgetCheckBoxArgs();
+
+                args.FieldName = "CheckBox1";
+                args.CheckStyle = C_CHECK_STYLE.CK_CHECK;
+                args.BorderStyle = C_BORDER_STYLE.BS_SOLID;
+                args.LineColor = Colors.Black;
+                args.BgColor = Colors.LightGreen;
+                args.LineWidth = 1;
+                checkBoxArgs = args;
                 PDFViewer.SetToolParam(checkBoxArgs);
             }
             else

+ 57 - 16
PDF Office/ViewModels/Form/FormBaseVM.cs

@@ -21,7 +21,32 @@ namespace PDF_Office.ViewModels.Form
         WidthSize,
         HeightSize,
         BorderColor,
-        ContentColor
+        ContentColor,
+        FillColor
+    }
+    public class ResetColor : BindableBase
+    {
+        private SolidColorBrush _borderColor;
+        public SolidColorBrush BorderColor
+        {
+            get { return _borderColor; }
+            set { SetProperty(ref _borderColor, value); }
+        }
+
+        private SolidColorBrush _fontColor;
+        public SolidColorBrush FontColor
+        {
+            get { return _fontColor; }
+            set { SetProperty(ref _fontColor, value); }
+        }
+
+
+        private SolidColorBrush _fillColor;
+        public SolidColorBrush FillColor
+        {
+            get { return _fillColor; }
+            set { SetProperty(ref _fillColor, value); }
+        }
     }
     public class FormBaseVM : BindableBase
     {
@@ -122,31 +147,47 @@ namespace PDF_Office.ViewModels.Form
             set { SetProperty(ref _contentColor, value); ChangeValueHandler?.Invoke(value, FormAttributeType.ContentColor); }
         }
 
+        //填充颜色
+        private Color _fillColor = Colors.Transparent;
+        public Color FillColor
+        {
+            get { return _fillColor; }
+            set { SetProperty(ref _fillColor, value); ChangeValueHandler?.Invoke(value, FormAttributeType.FillColor); }
+        }
+
         #endregion
-    }
 
-    public class ResetColor: BindableBase
-    {
-        private SolidColorBrush _borderColor;
-        public SolidColorBrush BorderColor
+        #region 颜色样式
+
+        private ResetColor _resetColorOne = new ResetColor();
+        public ResetColor ResetColorOne
         {
-            get { return _borderColor; }
-            set { SetProperty(ref _borderColor, value); }
+            get { return _resetColorOne; }
+            set { SetProperty(ref _resetColorOne, value); }
         }
 
-        private SolidColorBrush _fontColor;
-        public SolidColorBrush FontColor
+        private ResetColor _resetColorTwo = new ResetColor();
+        public ResetColor ResetColorTwo
         {
-            get { return _fontColor; }
-            set { SetProperty(ref _fontColor, value); }
+            get { return _resetColorTwo; }
+            set { SetProperty(ref _resetColorTwo, value); }
         }
 
+        private ResetColor _resetColorThree = new ResetColor();
+        public ResetColor ResetColorThree
+        {
+            get { return _resetColorThree; }
+            set { SetProperty(ref _resetColorThree, value); }
+        }
 
-        private SolidColorBrush _fillColor;
-        public SolidColorBrush FillColor
+        private ResetColor _resetColorForth = new ResetColor();
+        public ResetColor ResetColorForth
         {
-            get { return _fillColor; }
-            set { SetProperty(ref _fillColor, value); }
+            get { return _resetColorForth; }
+            set { SetProperty(ref _resetColorForth, value); }
         }
+
+        #endregion
     }
+
 }

+ 3 - 1
PDF Office/ViewModels/Form/FormsToolContentViewModel.cs

@@ -194,11 +194,12 @@ namespace PDF_Office.ViewModels.Form
 
             }
         }
+        // 选中时
         private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
         {
             if (e != null)
             {
-               // 选中时
+              
                 var annotHandlerEventArgs = e.AnnotItemsList[0];
                 if (annotHandlerEventArgs as WidgetArgs != null)
                 {
@@ -225,6 +226,7 @@ namespace PDF_Office.ViewModels.Form
         }
 
         public WidgetArgs CurrentWidgetArgs;
+        //新增
         private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {
            if(e != null && e.Count > 0)

+ 32 - 1
PDF Office/ViewModels/Form/ListBoxPropertyViewModel.cs

@@ -1,5 +1,6 @@
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Helper;
 using PDF_Office.Model;
 using Prism.Mvvm;
 using Prism.Regions;
@@ -46,6 +47,7 @@ namespace PDF_Office.ViewModels.Form
         #region 变量
         private CPDFViewer PDFViewer;
         private WidgetListBoxArgs listBoxArgs;
+        public UpdateAttributeHelper AttribEvent;
         #endregion
 
         #region 初始化
@@ -58,6 +60,33 @@ namespace PDF_Office.ViewModels.Form
         private void InitVariable()
         {
 
+            ResetColorOne = new ResetColor()
+            {
+                BorderColor = new SolidColorBrush(Colors.Transparent),
+                FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
+                FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00))
+            };
+
+            ResetColorTwo = new ResetColor()
+            {
+                BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
+                FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
+                FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00))
+            };
+
+            ResetColorThree = new ResetColor()
+            {
+                BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
+                FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
+                FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xBD, 0xDF, 0xFD))
+            };
+
+            ResetColorForth = new ResetColor()
+            {
+                BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xff, 0x00, 0x00)),
+                FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xff, 0x00, 0x00)),
+                FillColor = new SolidColorBrush(Colors.Transparent)
+            };
         }
 
         private void InitCommand()
@@ -96,16 +125,18 @@ namespace PDF_Office.ViewModels.Form
         {
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             navigationContext.Parameters.TryGetValue<WidgetListBoxArgs>("WidgetArgs", out listBoxArgs);
+            navigationContext.Parameters.TryGetValue<UpdateAttributeHelper>(ParameterNames.AnnotEvent, out AttribEvent);
 
             GetWidgeText();
         }
 
         private void GetWidgeText()
         {
-            PDFViewer.SetMouseMode(MouseModes.FormEditTool);
+          
 
             if (listBoxArgs == null)
             {
+                PDFViewer.SetMouseMode(MouseModes.FormEditTool);
                 listBoxArgs = new WidgetListBoxArgs();
                 listBoxArgs.BgColor = Colors.White;
                 listBoxArgs.FontFamily = "Courier New";

+ 24 - 31
PDF Office/ViewModels/Form/TextFieldPropertyViewModel.cs

@@ -59,35 +59,6 @@ namespace PDF_Office.ViewModels.Form
             set { SetProperty(ref _isScrollText, value); ChangeFieldValue("IsScrollText"); }
         }
 
-        private ResetColor _resetColorOne = new ResetColor();
-        public ResetColor ResetColorOne
-        {
-            get { return _resetColorOne; }
-            set { SetProperty(ref _resetColorOne, value); }
-        }
-
-        private ResetColor _resetColorTwo = new ResetColor();
-        public ResetColor ResetColorTwo
-        {
-            get { return _resetColorTwo; }
-            set { SetProperty(ref _resetColorTwo, value); }
-        }
-
-        private ResetColor _resetColorThree = new ResetColor();
-        public ResetColor ResetColorThree
-        {
-            get { return _resetColorThree; }
-            set { SetProperty(ref _resetColorThree, value); }
-        }
-
-        private ResetColor _resetColorForth = new ResetColor();
-        public ResetColor ResetColorForth
-        {
-            get { return _resetColorForth; }
-            set { SetProperty(ref _resetColorForth, value); }
-        }
-
-
         #endregion
 
         private FontFamily _fontFamily;
@@ -147,6 +118,7 @@ namespace PDF_Office.ViewModels.Form
 
         public DelegateCommand<object> IsMultiLineCheckedCommand { get; set; }
         public DelegateCommand<object> IsScrollToDisplayCheckedCommand { get; set; }
+        public DelegateCommand<object> LineStyleCommand { get; set; }
         #endregion
 
         #region 变量
@@ -214,10 +186,27 @@ namespace PDF_Office.ViewModels.Form
 
             IsMultiLineCheckedCommand = new DelegateCommand<object>(IsMultiLineChecked);
             IsScrollToDisplayCheckedCommand = new DelegateCommand<object>(IsScrollToDisplayChecked);
+            LineStyleCommand = new DelegateCommand<object>(LineStyleBtnEvent);
             ChangeValueHandler -= ChangeValue;
             ChangeValueHandler += ChangeValue;
         }
 
+        private void LineStyleBtnEvent(object obj)
+        {
+            if(obj != null)
+            {
+                switch((string)obj)
+                {
+                    case "Solid":
+                        IsSolid = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID;
+                        break;
+                    case "Dotted":
+                        IsSolid = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_DASHDED;
+                        break;
+                }
+            }
+        }
+
         private void IsScrollToDisplayChecked(object obj)
         {
            if(obj != null)
@@ -480,6 +469,7 @@ namespace PDF_Office.ViewModels.Form
             }
             else
             {
+  
                 PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
                 isCreateWidget = false;
             }
@@ -529,7 +519,7 @@ namespace PDF_Office.ViewModels.Form
 
                 case FormAttributeType.HeightSize:
                     textBoxArgs.DefaultWidth = HeightSize;
-                 //   AttribEvent?.UpdateAttrib(AnnotAttrib.h, HeightSize);
+                  //AttribEvent?.UpdateAttrib(AnnotAttrib.w, HeightSize);
                     break;
 
                 case FormAttributeType.BorderThiness:
@@ -546,6 +536,10 @@ namespace PDF_Office.ViewModels.Form
                     textBoxArgs.FontColor = ContentColor;
                     AttribEvent?.UpdateAttrib(AnnotAttrib.FontColor, ContentColor);
                     break;
+                case FormAttributeType.FillColor:
+                    textBoxArgs.BgColor = FillColor;
+                    AttribEvent?.UpdateAttrib(AnnotAttrib.FillColor, FillColor);
+                    break;
 
                 case FormAttributeType.IsReadOnly:
                     textBoxArgs.ReadOnly = IsReadOnly;
@@ -564,7 +558,6 @@ namespace PDF_Office.ViewModels.Form
 
             }
             AttribEvent?.UpdateAnnot();
-
         }
 
         private void ChangeFieldValue(string tag)

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 440 - 2
PDF Office/Views/Form/CheckBoxProperty.xaml


+ 30 - 1
PDF Office/Views/Form/CheckBoxProperty.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using PDF_Office.CustomControl;
+using PDF_Office.ViewModels.Form;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -20,9 +22,36 @@ namespace PDF_Office.Views.Form
     /// </summary>
     public partial class CheckBoxProperty : UserControl
     {
+        public CheckBoxPropertyViewModel ViewModel => DataContext as CheckBoxPropertyViewModel;
         public CheckBoxProperty()
         {
             InitializeComponent();
         }
+
+        private void EditMenuItem_Click(object sender, RoutedEventArgs e)
+        {
+            var Btnitem = sender as MenuItem;
+            if (Btnitem == null) return;
+            if (ViewModel != null)
+            {
+               // ViewModel.ResetColorCommand?.Execute(Btnitem);
+            }
+        }
+
+        private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
+        {
+            var btn = sender as CustomIconToggleBtn;
+            foreach (var item in PnlLineStyle.Children)
+            {
+                var btnItem = item as CustomIconToggleBtn;
+                if (btnItem != null)
+                {
+                    if (btn != btnItem)
+                        btnItem.IsChecked = false;
+                    else
+                        btnItem.IsChecked = true;
+                }
+            }
+        }
     }
 }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 492 - 2
PDF Office/Views/Form/ListBoxProperty.xaml


+ 30 - 1
PDF Office/Views/Form/ListBoxProperty.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using PDF_Office.CustomControl;
+using PDF_Office.ViewModels.Form;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -20,9 +22,36 @@ namespace PDF_Office.Views.Form
     /// </summary>
     public partial class ListBoxProperty : UserControl
     {
+        public ListBoxPropertyViewModel ViewModel => DataContext as ListBoxPropertyViewModel;
         public ListBoxProperty()
         {
             InitializeComponent();
         }
+
+        private void EditMenuItem_Click(object sender, RoutedEventArgs e)
+        {
+            var Btnitem = sender as MenuItem;
+            if (Btnitem == null) return;
+            if (ViewModel != null)
+            {
+               // ViewModel.ResetColorCommand?.Execute(Btnitem);
+            }
+        }
+
+        private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
+        {
+            var btn = sender as CustomIconToggleBtn;
+            foreach (var item in PnlLineStyle.Children)
+            {
+                var btnItem = item as CustomIconToggleBtn;
+                if (btnItem != null)
+                {
+                    if (btn != btnItem)
+                        btnItem.IsChecked = false;
+                    else
+                        btnItem.IsChecked = true;
+                }
+            }
+        }
     }
 }

+ 55 - 3
PDF Office/Views/Form/TextFieldProperty.xaml

@@ -215,6 +215,61 @@
                                     </i:EventTrigger>
                                 </i:Interaction.Triggers>
                             </CompositeControl:SlidComboControl>
+
+                            <StackPanel
+                x:Name="PnlLineStyle"
+                Margin="0,20,0,0"
+                Orientation="Horizontal">
+                                <cus:CustomIconToggleBtn
+                    x:Name="BtnSolidLine"
+                    Width="110"
+                    Height="32"
+                    Click="BtnLineStyle_Click"
+                    Command="{Binding LineStyleCommand}"
+                    CommandParameter="{Binding ElementName=BtnSolidLine, Path=Tag}"
+                    Style="{StaticResource ToggleBtnViewModeStyle}"
+                    Tag="Solid">
+                                    <Border
+                        Width="108"
+                        Height="30"
+                        Padding="8,0,8,0"
+                        BorderBrush="Black"
+                        BorderThickness="1">
+                                        <Line
+                            Stroke="Black"
+                            StrokeThickness="2"
+                            X1="10"
+                            X2="260"
+                            Y1="15"
+                            Y2="15" />
+                                    </Border>
+                                </cus:CustomIconToggleBtn>
+                                <cus:CustomIconToggleBtn
+                    x:Name="BtnDottedLine"
+                    Width="110"
+                    Height="32"
+                    Click="BtnLineStyle_Click"
+                    Command="{Binding LineStyleCommand}"
+                    CommandParameter="{Binding ElementName=BtnDottedLine, Path=Tag}"
+                    Style="{StaticResource ToggleBtnViewModeStyle}"
+                    Tag="Dotted">
+                                    <Border
+                        Width="108"
+                        Height="30"
+                        Padding="8,0,8,0"
+                        BorderBrush="Black"
+                        BorderThickness="1">
+                                        <Line
+                            Stroke="Black"
+                            StrokeDashArray="2"
+                            StrokeThickness="2"
+                            X1="10"
+                            X2="260"
+                            Y1="15"
+                            Y2="15" />
+                                    </Border>
+                                </cus:CustomIconToggleBtn>
+                            </StackPanel>
                         </StackPanel>
                         
                         
@@ -393,9 +448,6 @@
                         <CheckBox x:Name="MultiLineCheck" Content="Nulti-line"  Command="{Binding IsMultiLineCheckedCommand}" CommandParameter="{Binding ElementName=MultiLineCheck,Path=IsChecked}"/>
                         <CheckBox x:Name="ScrollToDisplayLongCheck" Content="Scroll to display long text"  Command="{Binding IsScrollToDisplayCheckedCommand}" CommandParameter="{Binding ElementName=ScrollToDisplayLongCheck,Path=IsChecked}"/>
                     </StackPanel>
-                    
-                    
-                    
 
                     <StackPanel Visibility="Collapsed" IsEnabled="{Binding ElementName=ChkLock, Path=IsChecked, Converter={StaticResource InvertBoolConvert}}">
                         <TextBlock

+ 18 - 1
PDF Office/Views/Form/TextFieldProperty.xaml.cs

@@ -1,4 +1,5 @@
-using PDF_Office.ViewModels.Form;
+using PDF_Office.CustomControl;
+using PDF_Office.ViewModels.Form;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -38,5 +39,21 @@ namespace PDF_Office.Views.Form
                 ViewModel.ResetColorCommand?.Execute(Btnitem);
             }
         }
+
+        private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
+        {
+            var btn = sender as CustomIconToggleBtn;
+            foreach (var item in PnlLineStyle.Children)
+            {
+                var btnItem = item as CustomIconToggleBtn;
+                if (btnItem != null)
+                {
+                    if (btn != btnItem)
+                        btnItem.IsChecked = false;
+                    else
+                        btnItem.IsChecked = true;
+                }
+            }
+        }
     }
 }