Parcourir la source

Form表单 - 布局对齐菜单

chenrongqian@kdanmobile.com il y a 2 ans
Parent
commit
b9d5b3a930

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

@@ -31,6 +31,14 @@ namespace PDF_Office.ViewModels.Form
             }
         }
 
+        //平均对齐布局
+        private bool _isLayoutAvgAlign = false;
+        public bool IsLayoutAvgAlign { get { return _isLayoutAvgAlign; } set { SetProperty(ref _isLayoutAvgAlign, value); } }
+        //对齐布局
+
+        private bool _isLayoutAlign = false;
+        public bool IsLayoutAlign { get { return _isLayoutAlign; } set { SetProperty(ref _isLayoutAlign, value); } }
+
         #endregion
 
         #region 变量
@@ -53,6 +61,8 @@ namespace PDF_Office.ViewModels.Form
         public DelegateCommand<string> CheckedCommand { get; set; }
         public DelegateCommand CancleCheckedCommand { get; set; }
         public DelegateCommand<string> ClickCommand { get; set; }
+        public DelegateCommand<object> AlignmentCheckedCommand { get; set; }
+        
 
         public event EventHandler<string> UncheckedToolsBtnEvent;
         
@@ -67,6 +77,7 @@ namespace PDF_Office.ViewModels.Form
             CheckedCommand = new DelegateCommand<string>(CheckedEvent);
             CancleCheckedCommand = new DelegateCommand(CancleChecked);
             ClickCommand = new DelegateCommand<string>(ClickEvent);
+            AlignmentCheckedCommand = new DelegateCommand<object>(AlignmentChecked);
             InitBtnToProperty();
         }
 
@@ -116,6 +127,41 @@ namespace PDF_Office.ViewModels.Form
             }
         }
 
+        private void AlignmentChecked(object obj)
+        {
+            if(obj != null)
+            {
+                var tag = (string)obj;
+                switch(tag)
+                {
+                    case "Left":
+                        PDFViewer.SetFormAligment(AlignModes.AlignLeft);
+                        break;
+                    case "Vertical":
+                        PDFViewer.SetFormAligment(AlignModes.AlignVerticalCenter);
+                        break;
+                    case "Right":
+                        PDFViewer.SetFormAligment(AlignModes.AlignRight);
+                        break;
+                    case "Top":
+                        PDFViewer.SetFormAligment(AlignModes.AlignTop);
+                        break;
+                    case "Horizontal":
+                        PDFViewer.SetFormAligment(AlignModes.AlignHorizonCenter);
+                        break;
+                    case "Lower":
+                        PDFViewer.SetFormAligment(AlignModes.AlignBottom);
+                        break;
+                    case "Distribute Vertical":
+                        PDFViewer.SetFormAligment(AlignModes.DistributeVertical);
+                        break;
+                    case "Distribute Horizontal":
+                        PDFViewer.SetFormAligment(AlignModes.DistributeHorizontal);
+                        break;
+                }
+            }
+        }
+
         private void AddToPropertyPanel(string type, WidgetArgs widget = null, UpdateAttributeHelper e = null)
         {
             if (btnToProperty.ContainsKey(type))
@@ -162,9 +208,10 @@ namespace PDF_Office.ViewModels.Form
         // 选中时
         private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
         {
+            int count = 0;
             if (e != null)
             {
-              
+                count = e.AnnotItemsList.Count;
                 var annotHandlerEventArgs = e.AnnotItemsList[0];
                 if (annotHandlerEventArgs as WidgetArgs != null)
                 {
@@ -176,6 +223,7 @@ namespace PDF_Office.ViewModels.Form
                         CurrentWidgetArgs.PageIndex == widgetArgs.PageIndex)
                     {
                         GetSelectWidget(widgetArgs, e);
+                        UpdateLayoutAlign(count);
                         return;
                     }
 
@@ -185,9 +233,28 @@ namespace PDF_Office.ViewModels.Form
                     UncheckedToolsBtnEvent?.Invoke(null, CurrentToolBtnType);
                     CurrentToolBtnType = "";
                 }
-
             }
 
+            UpdateLayoutAlign(count);
+        }
+
+        private void UpdateLayoutAlign(int count)
+        {
+            if (count == 0 || count == 1)
+            {
+                IsLayoutAlign = false;
+                IsLayoutAvgAlign = false;
+            }
+            else if (count == 2)
+            {
+                IsLayoutAlign = true;
+                IsLayoutAvgAlign = false;
+            }
+            else
+            {
+                IsLayoutAlign = true;
+                IsLayoutAvgAlign = true;
+            }
         }
 
         public WidgetArgs CurrentWidgetArgs;
@@ -278,7 +345,7 @@ namespace PDF_Office.ViewModels.Form
                 PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
             }
         }
-
+        
         #endregion
     }
 }

+ 57 - 8
PDF Office/Views/Form/FormsToolContent.xaml

@@ -177,15 +177,64 @@
                 </StackPanel>
                 <RadioButton.ContextMenu>
                     <ContextMenu Name="MenuAlignment" Placement="Bottom">
-                        <cus:MenuItemWithPath  Header="Left Alignment" Path="M2.01361 15V1H3.51361V15H2.01361ZM4.99994 4H10.9999V7H4.99994V4ZM13.9999 9H4.99994V12H13.9999V9Z" />
-                        <cus:MenuItemWithPath Header="Vertical Alignment" Path="M8.75006 7L8.75006 9L12.0001 9L12.0001 12L8.75006 12L8.75006 15L7.25006 15L7.25006 12L4.00006 12L4.00006 9L7.25006 9L7.25006 7L2.00006 7L2.00006 4L7.25006 4L7.25006 0.999999L8.75006 1L8.75006 4L14.0001 4L14.0001 7L8.75006 7Z" />
-                        <cus:MenuItemWithPath Header="Right Alignment" Path="M14.0001 1L14.0001 15L12.5001 15L12.5001 1L14.0001 1ZM11.0001 12L2.00006 12L2.00006 9L11.0001 9L11.0001 12ZM4.00006 7L11.0001 7L11.0001 4L4.00006 4L4.00006 7Z" />
-                        <cus:MenuItemWithPath Header="Top Alignment" Path="M15 2L1 2L1 3.5L15 3.5L15 2ZM12 5L12 11L9 11L9 5L12 5ZM7 5L7 14L4 14L4 5L7 5Z" />
-                        <cus:MenuItemWithPath Header="Horizontal Alignment" Path="M7 7.25L9 7.25L9 4L12 4L12 7.25L15 7.25L15 8.75L12 8.75L12 12L9 12L9 8.75L7 8.75L7 14L4 14L4 8.75L1 8.75L1 7.25L4 7.25L4 2L7 2L7 7.25Z" />
-                        <cus:MenuItemWithPath Header="Lower Alignment" Path="M9 2H12V11H9V2ZM4 5H7V11H4V5ZM1 14H15V12.5H1V14Z" />
-                        <cus:MenuItemWithPath Header="Distribute Vertical" Path="M15 12.5L1 12.5L1 14L15 14L15 12.5ZM12 9.5L4 9.5L4 6.5L12 6.5L12 9.5ZM1 2L15 2L15 3.5L1 3.5L1 2Z" />
-                        <cus:MenuItemWithPath Header="Distribute Horizontal" Path="M2 15V1H3.5V15H2ZM6.5 4H9.5V12H6.5V4ZM12.5 1V15H14V1H12.5Z" />
+                        <cus:MenuItemWithPath x:Name="LeftBtn" IsEnabled="{Binding IsLayoutAlign}" Header="Left Alignment" Tag="Left" Path="M2.01361 15V1H3.51361V15H2.01361ZM4.99994 4H10.9999V7H4.99994V4ZM13.9999 9H4.99994V12H13.9999V9Z">
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Left"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAlign}" Header="Vertical Alignment" Tag="Vertical" Path="M8.75006 7L8.75006 9L12.0001 9L12.0001 12L8.75006 12L8.75006 15L7.25006 15L7.25006 12L4.00006 12L4.00006 9L7.25006 9L7.25006 7L2.00006 7L2.00006 4L7.25006 4L7.25006 0.999999L8.75006 1L8.75006 4L14.0001 4L14.0001 7L8.75006 7Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Left"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAlign}" Header="Right Alignment" Tag="Right" Path="M14.0001 1L14.0001 15L12.5001 15L12.5001 1L14.0001 1ZM11.0001 12L2.00006 12L2.00006 9L11.0001 9L11.0001 12ZM4.00006 7L11.0001 7L11.0001 4L4.00006 4L4.00006 7Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Left"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAlign}" Header="Top Alignment" Tag="Top" Path="M15 2L1 2L1 3.5L15 3.5L15 2ZM12 5L12 11L9 11L9 5L12 5ZM7 5L7 14L4 14L4 5L7 5Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Top"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAlign}" Header="Horizontal Alignment" Tag="Horizontal" Path="M7 7.25L9 7.25L9 4L12 4L12 7.25L15 7.25L15 8.75L12 8.75L12 12L9 12L9 8.75L7 8.75L7 14L4 14L4 8.75L1 8.75L1 7.25L4 7.25L4 2L7 2L7 7.25Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Horizontal"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAlign}" Header="Lower Alignment" Tag="Lower" Path="M9 2H12V11H9V2ZM4 5H7V11H4V5ZM1 14H15V12.5H1V14Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Lower"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAvgAlign}" Header="Distribute Vertical" Tag="Distribute Vertical" Path="M15 12.5L1 12.5L1 14L15 14L15 12.5ZM12 9.5L4 9.5L4 6.5L12 6.5L12 9.5ZM1 2L15 2L15 3.5L1 3.5L1 2Z">
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Distribute Vertical"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
+                        <cus:MenuItemWithPath IsEnabled="{Binding IsLayoutAvgAlign}" Header="Distribute Horizontal" Tag="Distribute Horizontal" Path="M2 15V1H3.5V15H2ZM6.5 4H9.5V12H6.5V4ZM12.5 1V15H14V1H12.5Z" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Click">
+                                    <i:InvokeCommandAction Command="{Binding AlignmentCheckedCommand}" CommandParameter="Distribute Horizontal"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </cus:MenuItemWithPath>
                     </ContextMenu>
+                   
                 </RadioButton.ContextMenu>
             </RadioButton>
             <RadioButton Name="BtnMore" Width="44" Click="BtnMore_Click" Initialized="BtnMore_Initialized">