Ejemplo n.º 1
0
        public ToolBar InitializeToolBar(ToolBar toolBar, Guid toolBarGuid, IInputElement commandTarget)
        {
            InitializeToolBarItems();
            if (toolBar == null)
            {
                toolBar = new ToolBar();
                toolBar.FocusVisualStyle = null;
            }

            toolBar.Items.Clear();

            List <ToolBarItemGroupMD> groups;
            bool b = guidToGroups.TryGetValue(toolBarGuid, out groups);

            Debug.Assert(b);
            if (b)
            {
                var ctx = new ToolBarItemContext(toolBarGuid);

                var  items         = new List <ToolBarItemMD>();
                bool needSeparator = false;
                foreach (var group in groups)
                {
                    items.Clear();
                    foreach (var item in group.Items)
                    {
                        if (item.ToolBarItem.IsVisible(ctx))
                        {
                            items.Add(item);
                        }
                    }
                    if (items.Count == 0)
                    {
                        continue;
                    }
                    if (needSeparator)
                    {
                        toolBar.Items.Add(new Separator());
                    }
                    needSeparator = true;

                    foreach (var item in items)
                    {
                        var obj = Create(item, ctx, commandTarget);
                        if (obj != null)
                        {
                            toolBar.Items.Add(obj);
                        }
                    }
                }
            }

            CommandManager.InvalidateRequerySuggested();
            return(toolBar);
        }
Ejemplo n.º 2
0
        public ToolBar InitializeToolBar(ToolBar toolBar, Guid toolBarGuid, IInputElement commandTarget)
        {
            InitializeToolBarItems();
            if (toolBar == null) {
                toolBar = new ToolBar();
                toolBar.FocusVisualStyle = null;
            }

            toolBar.Items.Clear();

            List<ToolBarItemGroupMD> groups;
            bool b = guidToGroups.TryGetValue(toolBarGuid, out groups);
            Debug.Assert(b);
            if (b) {
                var ctx = new ToolBarItemContext(toolBarGuid);

                var items = new List<ToolBarItemMD>();
                bool needSeparator = false;
                foreach (var group in groups) {
                    items.Clear();
                    foreach (var item in group.Items) {
                        if (item.ToolBarItem.IsVisible(ctx))
                            items.Add(item);
                    }
                    if (items.Count == 0)
                        continue;
                    if (needSeparator)
                        toolBar.Items.Add(new Separator());
                    needSeparator = true;

                    foreach (var item in items) {
                        var obj = Create(item, ctx, commandTarget);
                        if (obj != null)
                            toolBar.Items.Add(obj);
                    }
                }
            }

            CommandManager.InvalidateRequerySuggested();
            return toolBar;
        }