コード例 #1
0
        private Button CreateButton(SdMenuInfo menuInfo)
        {
            var button = new Button
            {
                Content = menuInfo.Name,
                Height  = 20,
                Width   = 60
            };

            button.Click += (o, e) =>
            {
                var contextMenu = CreateContextMenu(button, menuInfo);
                contextMenu.IsOpen    = true;
                contextMenu.StaysOpen = true;
            };

            if (host != null)
            {
                host.Children.Add(host);
            }

            return(button);
        }
コード例 #2
0
        private ContextMenu CreateContextMenu(Button parent, SdMenuInfo menuInfo)
        {
            if (parent == null)
            {
                return(null);
            }

            var contextMenu = new ContextMenu
            {
                PlacementTarget = parent,
                Placement       = PlacementMode.Bottom,
            };

            if (menuInfo != null && menuInfo.Children != null && menuInfo.Children.Count > 0)
            {
                foreach (var child in menuInfo.Children)
                {
                    var subItem = CreateMenuItem(child);
                    contextMenu.Items.Add(subItem);
                }
            }

            return(contextMenu);
        }