Ejemplo n.º 1
0
        /// <summary>
        ///   This is the method that responds to the MouseButtonEvent event.
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            // Parent constrols such as RibbonComboBox don't want this item to acquire focus

            RibbonGallery gallery = RibbonGallery;

            if (gallery != null)
            {
                if (gallery.ShouldGalleryItemsAcquireFocus)
                {
                    Focus();
                }

                try
                {
                    gallery.HasHighlightChangedViaMouse = true;
                    IsHighlighted = true;
                }
                finally
                {
                    gallery.HasHighlightChangedViaMouse = false;
                }

                if (e.ButtonState == MouseButtonState.Pressed)
                {
                    IsPressed = true;
                }

                e.Handled = true;
            }

            base.OnMouseLeftButtonDown(e);
        }
        ///
        protected override List <AutomationPeer> GetChildrenCore()
        {
            RibbonGallery         owner = (RibbonGallery)Owner;
            List <AutomationPeer> baseAutomationPeers = new List <AutomationPeer>();

            if (!owner.IsGrouping)
            {
                baseAutomationPeers = base.GetChildrenCore();
            }


            if (owner.CanUserFilter)
            {
                UIElement filterHost = null;
                if (owner.FilterPaneContent != null || owner.FilterPaneContentTemplate != null)
                {
                    filterHost = owner.FilterContentPane;
                }
                else
                {
                    filterHost = owner.FilterMenuButton;
                }

                if (filterHost != null)
                {
                    baseAutomationPeers.Add(RibbonHelper.CreatePeer(filterHost));
                }
            }

            return(baseAutomationPeers);
        }
Ejemplo n.º 3
0
        // It just determines if any ancestor supports StarLayout and is not in StarLayoutPass mode.
        private bool IsAutoLayoutPass(double sumOfHeight, int childrenCount)
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                // Adding virtual count of items and cumulative height to RGC for the purpose of calcualting
                // avg height as scrolling delta in RibbonGalleryCategoriesPanel.
                category.averageItemHeightInfo.count            = childrenCount;
                category.averageItemHeightInfo.cumulativeHeight = sumOfHeight;
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    RibbonGalleryCategoriesPanel categoriesPanel = (RibbonGalleryCategoriesPanel)gallery.ItemsHostSite;
                    if (categoriesPanel != null)
                    {
                        IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)categoriesPanel;
                        if (iContainsStarLayoutManager.StarLayoutManager != null)
                        {
                            return(!iContainsStarLayoutManager.StarLayoutManager.IsStarLayoutPass);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   This is the method that responds to the MouseEvent event.
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            RibbonGallery gallery = RibbonGallery;

            if (gallery != null && gallery.DidMouseMove(e))
            {
                // Parent constrols such as RibbonComboBox don't want this item to acquire focus

                if (gallery.ShouldGalleryItemsAcquireFocus)
                {
                    Focus();
                }

                try
                {
                    gallery.HasHighlightChangedViaMouse = true;
                    IsHighlighted = true;
                }
                finally
                {
                    gallery.HasHighlightChangedViaMouse = false;
                }
                e.Handled = true;
            }

            base.OnMouseMove(e);
        }
Ejemplo n.º 5
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            RibbonGallery ribbonGallery = this.RibbonGallery;

            if (ribbonGallery != null)
            {
                // if (ribbonGallery.ShouldGalleryItemsAcquireFocus)
                // this.Focus();
                // try
                // {
                // ribbonGallery.HasHighlightChangedViaMouse = true;
                // this.IsHighlighted = true;
                // }
                // finally
                // {
                // ribbonGallery.HasHighlightChangedViaMouse = false;
                // }
                if (e.ButtonState == MouseButtonState.Pressed)
                {
                    this.IsPressed = true;
                }
                e.Handled = true;
            }
//            base.OnMouseLeftButtonDown(e);
        }
Ejemplo n.º 6
0
        // PreComputing MaxItemHeight and MaxItemWidth as the Measure algorithms of parent panels of Items will need it already
        // If it is in InRibbonGalleryMode.
        private void PreComputeMaxRibbonGalleryItemWidthAndHeight()
        {
            UIElementCollection children = InternalChildren;
            Size   childConstraint       = new Size(double.PositiveInfinity, double.PositiveInfinity);
            double maxItemHeight         = 0;
            int    childrenCount         = children.Count;
            double maxColumnWidth        = 0;

            for (int i = 0; i < childrenCount; i++)
            {
                RibbonGalleryCategory   child     = children[i] as RibbonGalleryCategory;
                RibbonGalleryItemsPanel itemPanel = child.ItemsHostSite as RibbonGalleryItemsPanel;
                if (itemPanel != null)
                {
                    int itemPanelChildrenCount = itemPanel.Children.Count;
                    for (int j = 0; j < itemPanelChildrenCount; j++)
                    {
                        RibbonGalleryItem item = (RibbonGalleryItem)itemPanel.Children[j];
                        item.Measure(childConstraint);
                        Size itemSize = item.DesiredSize;
                        maxColumnWidth = Math.Max(maxColumnWidth, itemSize.Width);
                        maxItemHeight  = Math.Max(maxItemHeight, itemSize.Height);
                    }
                }
            }

            RibbonGallery gallery = this.Gallery;

            if (gallery != null)
            {
                gallery.MaxItemHeight  = maxItemHeight;
                gallery.MaxColumnWidth = maxColumnWidth;
            }
        }
        ///
        protected override List <AutomationPeer> GetChildrenCore()
        {
            RibbonGallery         owner    = (RibbonGallery)Owner;
            List <AutomationPeer> children = null;

#if IN_RIBBON_GALLERY
            // If this is an InRibbonGallery, then we do not want the filter peer or the
            // RibbonGalleryCategory peers in the tree.  Add only the RibbonGalleryItem peers.
            if (owner.ParentInRibbonGallery != null &&
                owner.ParentInRibbonGallery.IsInInRibbonMode)
            {
                foreach (AutomationPeer categoryPeer in base.GetChildrenCore())
                {
                    foreach (AutomationPeer itemPeer in categoryPeer.GetChildren())
                    {
                        if (children == null)
                        {
                            children = new List <AutomationPeer>();
                        }

                        children.Add(itemPeer);
                    }
                }

                return(children);
            }
#endif

            if (!owner.IsGrouping)
            {
                children = base.GetChildrenCore();
            }

            if (owner.CanUserFilter)
            {
                UIElement filterHost = null;
                if (owner.FilterPaneContent != null || owner.FilterPaneContentTemplate != null)
                {
                    filterHost = owner.FilterContentPane;
                }
                else
                {
                    filterHost = owner.FilterMenuButton;
                }

                if (filterHost != null)
                {
                    if (children == null)
                    {
                        children = new List <AutomationPeer>(1);
                    }

                    children.Insert(0, RibbonHelper.CreatePeer(filterHost));
                }
            }

            return(children);
        }
Ejemplo n.º 8
0
 static public bool CmbSelect(RibbonGallery gal, string tag)
 {
     ContentControl item = CmbPick(gal.Items[0] as RibbonGalleryCategory, tag);
     if (item != null)
     {
         gal.SelectedItem = item;
         return true;
     }
     return false;
 }
Ejemplo n.º 9
0
        private void RibbonGallery_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RibbonGallery g    = sender as RibbonGallery;
            SkinId        skin = IdToSkin(g.SelectedIndex);

            if (Skin != skin)
            {
                Skin = skin;
            }
        }
Ejemplo n.º 10
0
        //private static DataSet ConvertJsonStringToDataSet(string jsonString)
        //{
        //    try
        //    {
        //        //XmlDocument xd = new XmlDocument();
        //        jsonString = jsonString.Trim().TrimStart('\"').TrimEnd('\"') ;
        //        string xd = JsonConvert.DeserializeXmlNode(jsonString).ToString();
        //        DataSet ds = new DataSet();
        //        //DataSet ds = JsonConvert.DeserializeObject<DataSet>(jsonString);
        //        //ds.ReadXml(new System.Xml.XmlNodeReader(xd));
        //        return ds;



        //        //Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();

        //        //json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
        //        //json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
        //        //json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
        //        //json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

        //        //StringReader sr = new StringReader(jsonString);
        //        //Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
        //        //DataSet result = json.Deserialize<DataSet>(reader);
        //        //reader.Close();

        //        //return result;

        //    }
        //    catch (Exception ex)
        //    {
        //        throw new ArgumentException(ex.Message);
        //    }
        //}


        protected void DDLBinding(int id, Semantics Stype)
        {
            String type      = Stype.ToString();
            string strResult = ProxyService.GetSemanticLists(id, type);

            strResult = strResult.Replace("\\", String.Empty);
            strResult = strResult.Trim().TrimStart('\"').TrimEnd('\"');
            var           objSerializer = new JavaScriptSerializer();
            var           obj           = objSerializer.Deserialize <List <SemanticList> >(strResult);
            RibbonGallery rbbnGallary   = null;

            switch (Stype)
            {
            case Semantics.abbreviation: rbbnGallary = glyAbbrevations;
                break;

            case Semantics.cite: rbbnGallary = glyCites;
                break;

            case Semantics.idiom: rbbnGallary = glyIdioms;
                break;

            case Semantics.variable: rbbnGallary = glyVariables;
                break;

            case Semantics.definition: rbbnGallary = glyDefinitions;
                break;

            case Semantics.links: rbbnGallary = glyLinks;
                break;

                //case "new": rbbnGallary = null;
                //    break;
            }
            if (rbbnGallary != null)
            {
                try
                {
                    for (int loop = 0; loop < obj.Count; loop++)
                    {
                        string strNameOfItem = obj[loop].Text;
                        Microsoft.Office.Tools.Ribbon.RibbonDropDownItem menuItem = Factory.CreateRibbonDropDownItem();
                        menuItem.Tag = obj[loop].Value;
                        //menuItem.Id = obj[loop].Value.ToString();
                        menuItem.Label = obj[loop].Text;

                        rbbnGallary.Items.Add(menuItem);
                        rbbnGallary.Items[loop].Label = strNameOfItem;
                    }
                }
                catch
                {
                }
            }
        }
        // Gets the MaxColumnWidth if the shared scope is Gallery
        // then MaxColumnWidth is used which is defined on Gallery to lay out all Items as Uniform width columns in scope of Gallery
        // otherwise they layout as Uniform width column within the scope of current Category only.
        private double GetMaxColumnWidth()
        {
            RibbonGallery gallery = Gallery;

            if (gallery != null && SharedColumnSizeScopeAtGalleryLevel)
            {
                return(gallery.MaxColumnWidth);
            }

            return(_maxColumnWidth);
        }
        private double GetArrangeWidth()
        {
            RibbonGallery gallery = Gallery;

            if (gallery != null && SharedColumnSizeScopeAtGalleryLevel)
            {
                return(gallery.ArrangeWidth);
            }

            return(_arrangeWidth);
        }
        // MaxItemHeight is the maximum height of an Item among all the Items of all categories in the gallery this panel is part of.
        // MaximumItemHeight is used by InRibbonGallery to find the Item Box for uniformity.
        private double GetMaxItemHeight()
        {
            RibbonGallery gallery = Gallery;

            if (gallery != null)
            {
                return(gallery.MaxItemHeight);
            }

            return(_maxItemHeight);
        }
 public override void Initialize(IComponent component)
 {
     base.Initialize(component);
     //
     this.m_RibbonGallery = base.Component as RibbonGallery;
     if (this.m_RibbonGallery == null)
     {
         this.DisplayError(new ArgumentException("RibbonGallery == null"));
         return;
     }
 }
Ejemplo n.º 15
0
        // In In RibbonMode only e first gallery if exist is accessible.
        protected override List <AutomationPeer> GetChildrenCore()
        {
            InRibbonGallery irg = (InRibbonGallery)Owner;

            if (irg.IsInInRibbonMode)
            {
                List <AutomationPeer> children = new List <AutomationPeer>();

                RibbonGallery firstGallery = irg.FirstGallery;
                if (firstGallery != null)
                {
                    AutomationPeer galleryPeer = UIElementAutomationPeer.CreatePeerForElement(firstGallery);
                    if (galleryPeer != null)
                    {
                        children.Add(galleryPeer);
                    }
                }

                RepeatButton scrollUpButton = irg.ScrollUpButton;
                if (scrollUpButton != null)
                {
                    AutomationPeer scrollUpButtonPeer = UIElementAutomationPeer.CreatePeerForElement(scrollUpButton);
                    if (scrollUpButtonPeer != null)
                    {
                        children.Add(scrollUpButtonPeer);
                    }
                }

                RepeatButton scrollDownButton = irg.ScrollDownButton;
                if (scrollDownButton != null)
                {
                    AutomationPeer scrollDownButtonPeer = UIElementAutomationPeer.CreatePeerForElement(scrollDownButton);
                    if (scrollDownButtonPeer != null)
                    {
                        children.Add(scrollDownButtonPeer);
                    }
                }

                ToggleButton partToggleButton = irg.PartToggleButton;
                if (partToggleButton != null)
                {
                    AutomationPeer partToggleButtonPeer = UIElementAutomationPeer.CreatePeerForElement(partToggleButton);
                    if (partToggleButtonPeer != null)
                    {
                        children.Add(partToggleButtonPeer);
                    }
                }

                return(children);
            }

            return(base.GetChildrenCore());
        }
        // Sets the ArrangeWidth on Gallery if the shared scope is Gallery
        private void SetArrangeWidth(double value)
        {
            _arrangeWidth = value;

            RibbonGallery gallery = Gallery;

            if (gallery != null && SharedColumnSizeScopeAtGalleryLevel)
            {
                gallery.ArrangeWidth        = value;
                gallery.IsArrangeWidthValid = true;
            }
        }
Ejemplo n.º 17
0
 // Select item in RibbonGallery by its tag
 private void SelectRibbonGalleryItem(
     RibbonGallery rg,
     object v)
 {
     for (int i = 0; i < rg.Items.Count; i++)
     {
         if ((string)rg.Items[i].Tag == v.ToString())
         {
             rg.SelectedIndex = i;
             return;
         }
     }
 }
Ejemplo n.º 18
0
        internal void ReInsertFirstGallery(InRibbonGallery irg)
        {
            RibbonGallery firstGallery = irg.FirstGallery;

            if (firstGallery != null &&
                _firstRibbonGalleryReInsertIndex >= 0)
            {
                Debug.Assert(_firstRibbonGalleryReInsertIndex <= InternalChildren.Count);

                InsertInternalChild(_firstRibbonGalleryReInsertIndex, firstGallery);
                _firstRibbonGalleryReInsertIndex = -1;
            }
        }
        private void SetMaxColumnWidthAndHeight(double maxWidth, double maxHeight)
        {
            SetMaxColumnWidth(maxWidth);

            RibbonGallery gallery = Gallery;

            if (gallery != null)
            {
                if (gallery.MaxItemHeight < maxHeight)
                {
                    gallery.MaxItemHeight = maxHeight;
                }
            }
        }
Ejemplo n.º 20
0
        private void RibbonGallery_HotThumbnailChanged(object sender, RoutedEventArgs e)
        {
            RibbonGallery   g     = sender as RibbonGallery;
            RibbonThumbnail thumb = g.HotThumbnail;

            if (thumb != null)
            {
                SkinManager.SkinId = IdToSkin(g.Items.IndexOf(g.HotItem));
            }
            else
            {
                SkinManager.SkinId = Skin;
            }
        }
Ejemplo n.º 21
0
        public void OnInitializeLayout()
        {
            IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this;

            if (iContainsStarLayoutManager.StarLayoutManager != null)
            {
                TreeHelper.InvalidateMeasureForVisualAncestorPath(this, RibbonHelper.IsISupportStarLayout);
                RibbonGallery gallery = this.Gallery;
                if (gallery != null)
                {
                    gallery.InvalidateMeasureOnAllCategoriesPanel();
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Click event handler for the gallery items displaying sample files
        /// </summary>
        /// <param name="sender">Gallery on the ribbon</param>
        /// <param name="e">RibbonControlEventArgs instance</param>
        private void OnViewSamplesGalleryClick(object sender, RibbonControlEventArgs e)
        {
            RibbonGallery gallery = sender as RibbonGallery;

            if (gallery != null)
            {
                // find out which item was clicked
                // read the file name
                string fileName = (string)gallery.SelectedItem.Tag;


                try
                {
                    // find the file path
                    string sampleFilePath = Path.Combine(Ribbon.GetAppInstallationLocation(), fileName);

                    // open the file in the excel instance
                    if (File.Exists(sampleFilePath))
                    {
                        int      wbCount  = ThisAddIn.ExcelApplication.Workbooks.Count;
                        Workbook targetWb = ThisAddIn.ExcelApplication.ActiveWorkbook;
                        Workbook wb       = ThisAddIn.ExcelApplication.Workbooks.Open(sampleFilePath, Type.Missing, true);

                        if (ThisAddIn.ExcelApplication.Workbooks.Count != wbCount)
                        {
                            Worksheet sourceWs = (Worksheet)wb.Worksheets[1];
                            Worksheet targetWs = (Worksheet)targetWb.Worksheets[1];
                            sourceWs.Copy(targetWs);
                            wb.Close(SaveChanges: false);
                        }
                    }
                    else
                    {
                        Ribbon.ShowError(Resources.SampleFileNotFound);
                    }
                }
                catch (CustomException ex)
                {
                    Ribbon.ShowError(ex.HasCustomMessage ? ex.Message : Resources.DefaultErrorMessage);
                }
                catch (COMException ex)
                {
                    Logger.LogException(ex);

                    // This is thrown when user says no in Re-open scenario
                    // Consume this exception
                }
            }
        }
Ejemplo n.º 23
0
        protected override void PrepareContainerForItemOverride(DependencyObject container, object item)
        {
            // If a new Gallery container has been generated for _galleryItem, update _gallery reference.
            RibbonGallery gallery = container as RibbonGallery;

            if (gallery != null)
            {
                if (_firstGalleryItem != null && _firstGalleryItem.IsAlive && _firstGalleryItem.Target.Equals(item))
                {
                    FirstGallery = gallery;
                }
            }

            base.PrepareContainerForItemOverride(container, item);
        }
Ejemplo n.º 24
0
        private void OnRibbonGalleryCategoriesPanelLoaded(object sender, RoutedEventArgs e)
        {
            RibbonGallery gallery = this.Gallery;

            if (gallery != null)
            {
#if IN_RIBBON_GALLERY
                if (gallery.IsInInRibbonGalleryMode())
                {
                    return;
                }
#endif
                RibbonHelper.InitializeStarLayoutManager(this);
            }
        }
Ejemplo n.º 25
0
        // Provides the visual UIElement which contains the CategoryData
        internal RibbonGalleryCategory GetOwningRibbonGalleryCategory()
        {
            RibbonGalleryCategory      owningRibbonGalleryCategory = null;
            ItemsControlAutomationPeer itemsControlAutomationPeer  = ItemsControlAutomationPeer;

            if (itemsControlAutomationPeer != null)
            {
                RibbonGallery gallery = (RibbonGallery)(itemsControlAutomationPeer.Owner);
                if (gallery != null)
                {
                    owningRibbonGalleryCategory = (RibbonGalleryCategory)gallery.ItemContainerGenerator.ContainerFromItem(Item);
                }
            }
            return(owningRibbonGalleryCategory);
        }
Ejemplo n.º 26
0
        // InRibbonGalleryMode where the gallery is shown within Ribbon via InRibbonGallery and Arrange
        // becomes responsibility of InRibbonGalleryModeArrangeOverride.
        private Size InRibbonGalleryModeArrangeOverride(Size finalSize)
        {
            UIElementCollection children = this.Children;
            Rect rcChild = new Rect(finalSize);

            //
            // Seed scroll offset into rcChild.
            //
            if (IsScrolling)
            {
                rcChild.X = -1.0 * _scrollData._offset.X;
                rcChild.Y = -1.0 * _scrollData._offset.Y;
            }

            // Arrange and Position Children. over each other as the items being arranged in child
            // in a way to respect the offset of where previous category children are ending.
            // It's merged wrapping.
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                RibbonGalleryCategory child = children[i] as RibbonGalleryCategory;

                if (child == null ||
                    child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                rcChild.Width = Math.Max(finalSize.Width, child.DesiredSize.Width);
                child.Arrange(rcChild);
            }

            // Refresh the IsEnabled state of the InRibbonGallery's LineUp & LineDown buttons.
            RibbonGallery gallery = Gallery;

            if (gallery != null)
            {
                InRibbonGallery irg = gallery.ParentInRibbonGallery;
                if (irg != null &&
                    irg.IsInInRibbonMode)
                {
                    irg.CoerceValue(InRibbonGallery.CanLineUpProperty);
                    irg.CoerceValue(InRibbonGallery.CanLineDownProperty);
                }
            }

            return(DesiredSize);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Click event handler for the feedback gallery
        /// </summary>
        /// <param name="sender">Feedback gallery</param>
        /// <param name="e">Ribbon control event arguments</param>
        private void OnFeedbackGalleryClick(object sender, RibbonControlEventArgs e)
        {
            RibbonGallery gallery = sender as RibbonGallery;

            if (gallery != null)
            {
                RibbonDropDownItem selectedItem = (RibbonDropDownItem)gallery.SelectedItem;
                if (selectedItem.Label == Resources.FeedbackSurveyLabel)
                {
                    StartProcess(Common.Constants.FeedbackLink);
                }
                else if (selectedItem.Label == Resources.VisitForumLabel)
                {
                    StartProcess(Common.Constants.VisitForumLink);
                }
            }
        }
Ejemplo n.º 28
0
        // Gets the MaxColumnWidth if the shared scope is Gallery (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
        // then MaxColumnWidth is used which is defined on Gallery to lay out all Items as Uniform width columns in scope of Gallery
        // otherwise they layout as Uniform width column within the scope of current Category only.
        private double GetMaxColumnWidth()
        {
            RibbonGalleryCategory category = (RibbonGalleryCategory)ItemsControl.GetItemsOwner(this);

            if (category != null)
            {
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    if (gallery.IsSharedColumnSizeScope && !category.IsSharedColumnSizeScope)
                    {
                        return(gallery.MaxColumnWidth);
                    }
                }
            }
            return(_maxColumnWidth);
        }
Ejemplo n.º 29
0
        private static void OnIsHighlightedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonGalleryItem galleryItem = (RibbonGalleryItem)d;
            bool isHighlighted            = (bool)e.NewValue;

            RibbonGalleryCategory category = galleryItem.RibbonGalleryCategory;

            if (category != null)
            {
                RibbonGallery gallery = category.RibbonGallery;
                if (gallery != null)
                {
                    // Give the RibbonGallery a reference to this container and its data
                    object item = category.ItemContainerGenerator.ItemFromContainer(galleryItem);
                    gallery.ChangeHighlight(item, galleryItem, isHighlighted);
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Cache container reference and RibbonGallery for first gallery.
        /// </summary>
        private void UpdateFirstGallery()
        {
            _firstGalleryItem = null;
            _firstGallery     = null;
            CommandTarget     = null;

            foreach (object item in Items)
            {
                RibbonGallery firstGallery = ItemContainerGenerator.ContainerFromItem(item) as RibbonGallery;
                if (firstGallery != null)
                {
                    _firstGalleryItem = new WeakReference(item);
                    FirstGallery      = firstGallery;
                    CommandTarget     = firstGallery.ScrollViewer;
                    return;
                }
            }
        }