Prechádzať zdrojové kódy

注释 - 创建右键菜单、获取虚线实线

chenrongqian@kdanmobile.com 2 rokov pred
rodič
commit
fd9530d8b2

+ 151 - 0
PDF Office/Helper/PopControlHelper.cs

@@ -507,6 +507,157 @@ namespace PDF_Office.Helper
 
     }
 
+    public class CusMenuItem
+    {
+        public Control control { get; private set; }
+        public object Parameter { get; private set; }
+        public object tag { get; private set; }
+        public void SetFlagControl(Control control)
+        {
+            this.control = control;
+            tag = control.Tag;
+        }
+
+        public void SetParameter(object parameter)
+        {
+            Parameter = parameter;
+        }
+    }
+    public class PopMenu
+    {
+        public ContextMenu ContMenu { get; private set; }
+        public List<CusMenuItem> Controls { get; private set; }
+        public PopMenu(ContextMenu popMenu,Style style = null)
+        {
+            if (style != null)
+                popMenu.Style = style;
+
+            ContMenu = popMenu;
+        }
+
+        //打开右键菜单
+        public ContextMenu OpenMenu(object parameter)
+        {
+            if (Controls == null) return null;
+
+            foreach(var item in Controls)
+            {
+                BindingParameter(item, parameter);
+            }
+
+            return ContMenu;
+        }
+
+        //右键菜单:创建菜单按钮、单选按钮
+        public CusMenuItem AddItem(Control control,Style style = null)
+        {
+            if (control == null) return null;
+
+            if (style != null)
+                control.Style = style;
+
+            CusMenuItem controlMenu = new CusMenuItem();
+            controlMenu.SetFlagControl(control);
+            if (Controls == null)
+                Controls = new List<CusMenuItem>();
+
+            ContMenu.Items.Add(controlMenu.control);
+            Controls.Add(controlMenu);
+
+            return controlMenu;
+        }
+
+        public CusMenuItem AddChild(string parentName, Control child, Style style = null)
+        {
+            if (Controls == null || child == null) return null;
+
+            if (style != null)
+                child.Style = style;
+
+            CusMenuItem childItem = null;
+            foreach (var item in Controls)
+            {
+                var menu = item.control as MenuItem;
+
+                if (menu != null && menu.Name == parentName)
+                {
+                    childItem = new CusMenuItem();
+                    childItem.SetFlagControl(child);
+                    menu.Items.Add(child);
+                    break;
+                }
+            }
+
+            return childItem;
+        }
+
+        //菜单按钮事件绑定
+        public void BindingEvent(CusMenuItem controlMenu,ICommand command, object CommandParameter)
+        {
+            if (controlMenu == null) return;
+
+            if(controlMenu.control is RadioButton)
+            {
+                var Btn = (RadioButton)controlMenu.control;
+                Btn.CommandParameter = controlMenu;
+                Btn.Command = command;
+            }
+            else if(controlMenu.control is MenuItem)
+            {
+                var Btn = (MenuItem)controlMenu.control;
+
+                if(CommandParameter is UIElement)
+                {
+                    Btn.CommandTarget = (UIElement)CommandParameter;
+                }
+
+                Btn.CommandParameter = controlMenu;
+                Btn.Command = command;
+            }
+
+            controlMenu.SetParameter(CommandParameter);
+        }
+
+        private void BindingParameter(CusMenuItem controlMenu, object CommandParameter)
+        {
+            if (controlMenu == null) return;
+
+            if (controlMenu.control is RadioButton)
+            {
+                var Btn = (RadioButton)controlMenu.control;
+                Btn.CommandParameter = controlMenu;
+            }
+            else if (controlMenu.control is MenuItem)
+            {
+                var Btn = (MenuItem)controlMenu.control;
+
+                if (CommandParameter is UIElement)
+                {
+                    Btn.CommandTarget = (UIElement)CommandParameter;
+                }
+
+                Btn.CommandParameter = controlMenu;
+            }
+
+            controlMenu.SetParameter(CommandParameter);
+        }
+
+        //菜单按钮是否可见
+        public void SetVisual(string name,bool isVisible)
+        {
+            if (Controls == null) return;
+
+            foreach(var item in Controls)
+            {
+                if(item.control.Name == name)
+                {
+                    item.control.Visibility = (isVisible?Visibility.Visible:Visibility.Collapsed);
+                    break;
+                }
+            }
+        }
+    }
+
     #endregion
 
 }

+ 3 - 3
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SharpsAnnotPropertyViewModel.cs

@@ -480,17 +480,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             if (annot is SquareAnnotArgs)
             {
                 var Square = Annot as SquareAnnotArgs;
-                isSolid = PropertyPanel.IsSolidStyle(Square.LineDash);
+                isSolid = AnnotPropertyPanel.IsSolidStyle(Square.LineDash);
             }
             else if(annot is CircleAnnotArgs)
             {
                 var Circle = Annot as CircleAnnotArgs;
-                isSolid = PropertyPanel.IsSolidStyle(Circle.LineDash);
+                isSolid = AnnotPropertyPanel.IsSolidStyle(Circle.LineDash);
             }
             else if(annot is LineAnnotArgs)
             {
                 var line = Annot as LineAnnotArgs;
-                isSolid = PropertyPanel.IsSolidStyle(line.LineDash);
+                isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
             }
 
             return isSolid;

+ 27 - 15
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -1037,46 +1037,58 @@ namespace PDF_Office.ViewModels.Tools
                 var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
                 if (annot is TextHighlightAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color,Settings.Default.AppProperties.Annotate.HighLightColor);
+                    var color = (annot as TextHighlightAnnotArgs).Color;
+                    Settings.Default.AppProperties.Annotate.HighLightColor = color;
+                    HighLightColor = new SolidColorBrush(color);
                 }
                 else if(annot is TextUnderlineAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.UnderLineColor);
+                    var color = (annot as TextHighlightAnnotArgs).Color;
+                    Settings.Default.AppProperties.Annotate.UnderLineColor = color;
+                    UnderLineColor = new SolidColorBrush(color);
                 }
                 else if (annot is TextStrikeoutAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.StrikethroughColor);
+                    var color = (annot as TextHighlightAnnotArgs).Color;
+                    Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
+                    StrikeoutColor = new SolidColorBrush(color);
                 }
                 else if (annot is FreehandAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.FreeHandColor);
+                    var color = (annot as FreehandAnnotArgs).InkColor;
+                    Settings.Default.AppProperties.Annotate.FreeHandColor = color;
+
                 }
                 else if (annot is FreeTextAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.TextAnnoteColor);
-                   // AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, Settings.Default.AppProperties.Annotate.TextFontFamaily);
-                   // AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, Settings.Default.AppProperties.Annotate.TextAlign);
+                    var color = (annot as FreeTextAnnotArgs).FontColor;
+                    Settings.Default.AppProperties.Annotate.TextAnnoteColor = color;
                 }
                 else if (annot is StickyAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.NoteAnnoteColor);
+                    var color = (annot as StickyAnnotArgs).Color;
+                    Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
                 }
                 else if (annot is SquareAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, Settings.Default.AppProperties.Annotate.RectangleFillColor);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.RectangleBorderColor);
+                    var bgColor = (annot as SquareAnnotArgs).BgColor;
+                    Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
+                    var borderColor = (annot as SquareAnnotArgs).LineColor;
+                    Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
                 }
                 else if (annot is CircleAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, Settings.Default.AppProperties.Annotate.CircleFillColor);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.CircleBorderColor);
+                    var bgColor = (annot as CircleAnnotArgs).BgColor;
+                    Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
+                    var borderColor = (annot as CircleAnnotArgs).LineColor;
+                    Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
                 }
                 else if (annot is LineAnnotArgs)
                 {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, Settings.Default.AppProperties.Annotate.LineColor);
+                    var color = (annot as LineAnnotArgs).LineColor;
+                    Settings.Default.AppProperties.Annotate.LineColor = color;
                 }
-
-                AnnotEvent?.UpdateAnnot();
+                Settings.Default.Save();
             }
         }
 

+ 41 - 13
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs

@@ -339,22 +339,50 @@ namespace PDF_Office.ViewModels.Tools
         //高亮注释,右键菜单
         private ContextMenu SelectHightAnnotMenu(object sender)
         {
-            var popMenu = App.Current.FindResource("HightAnnotContextMenu") as ContextMenu;
-            CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
-            //颜色列表
+            var popMenu = new ContextMenu();
+            PopMenu pop = new PopMenu(popMenu);
             ColorContent colorContent = new ColorContent();
-            colorContent.DataContext = sender;
+            colorContent.Name = "hightcolor";
             colorContent.SelectedColorHandler -= colorContent_SelectedColorHandler;
             colorContent.SelectedColorHandler += colorContent_SelectedColorHandler;
-            customMenu.SetMenuUI(0,colorContent);
-            //复制文本
-            customMenu.SetMenuBinding(1, HightAnnotCopyText_MenuCommand);
-            //删除
-            customMenu.SetMenuBinding(2, ApplicationCommands.Delete);
-            //添加笔记
-            customMenu.SetMenuBinding(3, AnnotAddNoteText_MenuCommand);
-            //设置当前属性为默认值
-            customMenu.SetMenuBinding(4, AnnotDefaultValue_MenuCommand);
+            pop.AddItem(colorContent);
+
+            var menuItem = new MenuItem();
+            menuItem.Name = "hightCopyText";
+            menuItem.Header = "复制文本";
+            pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand, sender);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "hightdelete";
+            menuItem.Header = "删除";
+            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete, sender);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "hightAddNote";
+            menuItem.Header = "添加笔记";
+            pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand, sender);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "hightdefault";
+            menuItem.Header = "设置当前属性为默认值";
+            pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand, sender);
+
+            //var popMenu = App.Current.FindResource("HightAnnotContextMenu") as ContextMenu;
+            //CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
+            ////颜色列表
+            //ColorContent colorContent = new ColorContent();
+            //colorContent.DataContext = sender;
+            //colorContent.SelectedColorHandler -= colorContent_SelectedColorHandler;
+            //colorContent.SelectedColorHandler += colorContent_SelectedColorHandler;
+            //customMenu.SetMenuUI(0,colorContent);
+            ////复制文本
+            //customMenu.SetMenuBinding(1, HightAnnotCopyText_MenuCommand);
+            ////删除
+            //customMenu.SetMenuBinding(2, ApplicationCommands.Delete);
+            ////添加笔记
+            //customMenu.SetMenuBinding(3, AnnotAddNoteText_MenuCommand);
+            ////设置当前属性为默认值
+            //customMenu.SetMenuBinding(4, AnnotDefaultValue_MenuCommand);
             return popMenu;
         }