Przeglądaj źródła

右键菜单 - 自定义右键菜单,command绑定,更改属性值

chenrongqian@kdanmobile.com 2 lat temu
rodzic
commit
cf0a92d574

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

@@ -12,6 +12,7 @@ using static PDF_Office.CustomControl.ColorDropBox;
 
 namespace PDF_Office.Helper
 {
+    #region 悬浮窗口
     public class AdornerPresenter : Adorner
     {
         private VisualCollection VisualChildren;
@@ -212,4 +213,61 @@ namespace PDF_Office.Helper
         }
 
     }
+
+    #endregion
+
+    #region 自定义菜单
+    //自定义菜单:事件绑定、内容等
+
+    public class CustomPopMenu
+    {
+        public ContextMenu PopMenu { get; private set; }
+        public CustomPopMenu(ContextMenu popMenu)
+        {
+            PopMenu = popMenu;
+        }
+
+        private MenuItem ContainterOfIndex(int index)
+        {
+            if (PopMenu == null || PopMenu.Items.Count < index || index < 0)
+                return null;
+
+            MenuItem menuItem = PopMenu.Items[index] as MenuItem;
+            return menuItem;
+        }
+
+        public void SetVisibilityProperty(int index, bool isVisual)
+        {
+            var menuItem = ContainterOfIndex(index);
+            if (menuItem != null)
+            {
+                menuItem.Visibility = (isVisual?Visibility.Visible:Visibility.Collapsed);
+            }
+        }
+        public void SetHeaderProperty(int index, string header)
+        {
+            var menuItem = ContainterOfIndex(index);
+
+            if (menuItem != null)
+            {
+                menuItem.Header = header;
+            }
+        }
+
+        public void SetMenuBinding(int index, object commandTarget, ICommand command)
+        {
+            var menuItem = ContainterOfIndex(index);
+
+            if (menuItem != null)
+            {
+                menuItem.CommandTarget = (UIElement)commandTarget;
+                menuItem.Command = command;
+            }
+
+        }
+
+    }
+
+    #endregion
+
 }

+ 18 - 0
PDF Office/Styles/ContextMenuStyle.xaml

@@ -20,6 +20,24 @@
             </MenuItem.Icon>
         </MenuItem>
     </ContextMenu>
+    
+    <ContextMenu x:Key="CustomFontStyleFlyoutMenu" FontSize="14">
+        <ContextMenu.ItemContainerStyle>
+            <Style TargetType="MenuItem">
+                <Setter Property="Padding" Value="0,7,0,7" />
+                <Setter Property="VerticalContentAlignment" Value="Center" />
+            </Style>
+        </ContextMenu.ItemContainerStyle>
+        <MenuItem
+                    Name="ChangeStyleMenuItem"
+                    Header="用所选部分重新定义"
+                    IsEnabled="True" />
+        <MenuItem
+                    Name="BackStyleMenuItem"
+                    Header="恢复默认预设样式"
+                    IsEnabled="True" />
+    </ContextMenu>
+
 
     <ContextMenu x:Key="SelectAnnotContextMenu" FontSize="14">
         <ContextMenu.ItemContainerStyle>