예제 #1
0
        /// <summary>
        /// Adds a clone of the item to the Items collection.
        /// </summary>
        public void Add(ISupportQuickAccessToolBar item)
        {
            if (IsLocked)
            {
                return;
            }

            string id = GetEffectiveId((DependencyObject)item);

            if (Contains(id))
            {
                return;
            }

            var clone = item.CloneForQuickAccessToolbar();

            SetId(clone, id);
            clone.SetValue(IsCloneProperty, true);
            InsertItem(clone);
        }
예제 #2
0
        private ISupportQuickAccessToolBar FindQATSupporter(string id, ref List <ISupportQuickAccessToolBar> qatSupporters)
        {
            var window = Window.GetWindow(this);

            if (window == null)
            {
                return(null);
            }

            if (qatSupporters == null)
            {
                qatSupporters = window.GetVisuals <ISupportQuickAccessToolBar>().ToList();
            }

            foreach (var qatSupporter in qatSupporters)
            {
                if (GetEffectiveId((DependencyObject)qatSupporter) == id)
                {
                    return(qatSupporter);
                }
            }

            var metroShell = window.GetFirstDescendent <MetroShell>();

            if (metroShell == null)
            {
                return(null);
            }

            var selectedTab = metroShell.SelectedItem;
            ISupportQuickAccessToolBar target = null;

            try
            {
                foreach (var item in metroShell.Items)
                {
                    if (item != selectedTab)
                    {
                        metroShell.SelectedItem = item;
                        DispatcherHelper.WaitForPriority(DispatcherPriority.ContextIdle);
                        var supporters = metroShell.GetVisuals <ISupportQuickAccessToolBar>().ToList();
                        qatSupporters.AddRange(supporters);
                        foreach (var qatSupporter in supporters)
                        {
                            if (GetEffectiveId((DependencyObject)qatSupporter) == id)
                            {
                                target = qatSupporter;
                                break;
                            }
                        }
                    }

                    if (target != null)
                    {
                        break;
                    }
                }
            }
            catch { } // Don't want unexpected errors to cause a crash. Doing something a bit unusual after all...
            finally
            {
                metroShell.SelectedItem = selectedTab;
            }
            return(target);
        }
예제 #3
0
 /// <summary>
 /// Returns true if an element based on item has been added to the QAT.
 /// </summary>
 public bool Contains(ISupportQuickAccessToolBar item)
 {
     return(Contains(GetEffectiveId((DependencyObject)item)));
 }