예제 #1
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            object currentItem = _currentItem;

            _currentItem = null;

            if (UsesItemContainerTemplate)
            {
                DataTemplate itemContainerTemplate = ItemContainerTemplateSelector.SelectTemplate(currentItem, this);
                if (itemContainerTemplate != null)
                {
                    object itemContainer = itemContainerTemplate.LoadContent();
                    if (itemContainer is RibbonApplicationMenuItem || itemContainer is RibbonApplicationSplitMenuItem || itemContainer is RibbonSeparator || itemContainer is RibbonGallery)
                    {
                        return(itemContainer as DependencyObject);
                    }
                    else
                    {
                        throw new InvalidOperationException(Microsoft.Windows.Controls.SR.Get(Microsoft.Windows.Controls.SRID.InvalidApplicationMenuOrItemContainer, this.GetType().Name, itemContainer));
                    }
                }
            }

            return(new RibbonApplicationMenuItem());
        }
예제 #2
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            object currentItem = _currentItem;

            _currentItem = null;

            if (UsesItemContainerTemplate)
            {
                DataTemplate itemContainerTemplate = ItemContainerTemplateSelector.SelectTemplate(currentItem, this);
                if (itemContainerTemplate != null)
                {
                    object itemContainer = itemContainerTemplate.LoadContent();
                    if (itemContainer is MenuItem || itemContainer is Separator)
                    {
                        return(itemContainer as DependencyObject);
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InvalidItemContainer, this.GetType().Name, typeof(MenuItem).Name, typeof(Separator).Name, itemContainer));
                    }
                }
            }

            return(new MenuItem());
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override DependencyObject GetContainerForItemOverride()
        {
            var currentItem = _currentItem;

            _currentItem = (object)null;
            if (UsesItemContainerTemplate)
            {
                var dataTemplate = ItemContainerTemplateSelector.SelectTemplate(currentItem, (ItemsControl)this);
                if (dataTemplate != null)
                {
                    var obj = (object)dataTemplate.LoadContent();
                    switch (obj)
                    {
                    case RibbonMenuItem _:
                    case RibbonGallery _:
                    case RibbonSeparator _:
                        return(obj as DependencyObject);

                    default:
                        throw new InvalidOperationException("Invalid container");
                    }
                }
            }

            return((DependencyObject) new RibbonMenuItem());
        }
        protected override DependencyObject GetContainerForItemOverride()
        {
            var currentItem = _currentItem;

            _currentItem = null;

            if (UsesItemContainerTemplate)
            {
                var dataTemplate = ItemContainerTemplateSelector.SelectTemplate(currentItem, this);
                if (dataTemplate == null)
                {
                    return(new RibbonMenuItem());
                }

                object templateContent = dataTemplate.LoadContent();
                if (templateContent is MenuItem item)
                {
                    return(item);
                }

                throw new InvalidOperationException("InvalidApplicationMenuOrItemContainer");
            }

            if (currentItem is IIsSeparatorAware isSeparatorAware && isSeparatorAware.IsSeparator)
            {
                return(new RibbonSeparator());
            }

            return(new RibbonMenuItem());
        }
        protected override DependencyObject GetContainerForItemOverride()
        {
            var currentItem = _currentItem;

            _currentItem = null;

            if (UsesItemContainerTemplate)
            {
                var dataTemplate = ItemContainerTemplateSelector.SelectTemplate(currentItem, this);
                if (dataTemplate == null)
                {
                    return(new RibbonMenuItem());
                }

                object templateContent = dataTemplate.LoadContent();
                if (templateContent is System.Windows.Controls.Ribbon.RibbonMenuItem ||
                    templateContent is System.Windows.Controls.Ribbon.RibbonSeparator ||
                    templateContent is RibbonGallery)
                {
                    return((DependencyObject)templateContent);
                }

                throw new InvalidOperationException("InvalidApplicationMenuOrItemContainer");
            }

            return(new RibbonMenuItem());
        }
예제 #6
0
        /// <summary>
        /// Create menu item container
        /// </summary>
        protected virtual View CreateItemContainer(object model)
        {
            View item = null;

            if (ItemContainerTemplateSelector != null)
            {
                DataTemplate containerTemplate = ItemContainerTemplateSelector.SelectTemplate(model, null) as DataTemplate;
                item = containerTemplate.CreateContent() as View;
            }
            else if (ItemContainerTemplate != null)
            {
                item = ItemContainerTemplate.CreateContent() as View;
            }
            else
            {
                item = new ContentView();
            }

            if (item == null)
            {
                throw new Exception("ItemContainerTemplate is not subclass of ContentView");
            }

            item.BindingContext = model;
            return(item);
        }
 public static T ItemContainerTemplateSelector <T>(this T source, ItemContainerTemplateSelector value) where T : MenuBase
 {
     source.ItemContainerTemplateSelector = value;
     return(source);
 }