Пример #1
0
        private void CreateSuperMenuItem(SuperMenuItemData data, ItemsControl parent)
        {
            if (data.Children != null)
            {
                SuperMenuItem groupMenuItem = new SuperMenuItem();
                groupMenuItem.SetBinding(SuperMenuItem.HeaderProperty, new Binding(nameof(data.Name))
                {
                    Mode = BindingMode.TwoWay
                });
                groupMenuItem.SetBinding(SuperMenuItem.VisibilityProperty, new Binding(nameof(data.Visibility))
                {
                    Mode = BindingMode.TwoWay
                });
                groupMenuItem.SetBinding(SuperMenuItem.IsEnabledProperty, new Binding(nameof(data.Enable))
                {
                    Mode = BindingMode.TwoWay
                });
                groupMenuItem.DataContext = data;
                parent.Items.Add(groupMenuItem);

                foreach (var item in data.Children)
                {
                    CreateSuperMenuItem(item, groupMenuItem);
                }
            }
            else if (data.ItemType == MenuItemType.Separator)
            {
                Separator sp = new Separator();
                sp.SetBinding(Separator.VisibilityProperty, new Binding(nameof(data.Visibility))
                {
                    Mode = BindingMode.TwoWay
                });
                sp.SetBinding(Separator.IsEnabledProperty, new Binding(nameof(data.Enable))
                {
                    Mode = BindingMode.TwoWay
                });
                sp.DataContext = data;
                parent.Items.Add(sp);
            }
            else
            {
                SuperMenuItem item = new SuperMenuItem();
                item.SetBinding(SuperMenuItem.HeaderProperty, new Binding(nameof(data.Name))
                {
                    Mode = BindingMode.TwoWay
                });
                item.SetBinding(SuperMenuItem.VisibilityProperty, new Binding(nameof(data.Visibility))
                {
                    Mode = BindingMode.TwoWay
                });
                item.SetBinding(SuperMenuItem.IsEnabledProperty, new Binding(nameof(data.Enable))
                {
                    Mode = BindingMode.TwoWay
                });
                item.Click      += data.MenuItemClick;
                item.DataContext = data;
                parent.Items.Add(item);
            }
        }
Пример #2
0
        public void CheckItemAccess(SuperMenuItemData item)
        {
            //if (item.NoAccessUserGroups != null && item.NoAccessUserGroups.Any(i => i == IApp.loginUser.GROUPID))
            //{
            //    item.Visibility = Visibility.Collapsed;
            //}
            //else
            //{
            //    item.Visibility = Visibility.Visible;
            //}

            if (item.Children != null)
            {
                foreach (var citem in item.Children)
                {
                    CheckItemAccess(citem);
                }
            }
        }