示例#1
0
        internal void CloseThisTabItem([NotNull] MetroTabItem tabItem)
        {
            if (tabItem == null)
            {
                throw new ArgumentNullException(nameof(tabItem));
            }

            if (this.CloseTabCommand != null)
            {
                var closeTabCommandParameter = tabItem.CloseTabCommandParameter ?? tabItem;
                if (this.CloseTabCommand.CanExecute(closeTabCommandParameter))
                {
                    this.CloseTabCommand.Execute(closeTabCommandParameter);
                }
            }
            else
            {
                // KIDS: don't try this at home
                // this is not good MVVM habits and I'm only doing it
                // because I want the demos to be absolutely bitching

                // the control is allowed to cancel this event
                if (this.RaiseTabItemClosingEvent(tabItem))
                {
                    return;
                }

                if (this.ItemsSource == null)
                {
                    // if the list is hard-coded (i.e. has no ItemsSource)
                    // then we remove the item from the collection
                    this.Items.Remove(tabItem);
                }
                else
                {
                    // if ItemsSource is something we cannot work with, bail out
                    var collection = this.ItemsSource as IList;
                    if (collection == null)
                    {
                        return;
                    }

                    // find the item and kill it (I mean, remove it)
                    var item2Remove = collection.OfType <object>().FirstOrDefault(item => tabItem == item || tabItem.DataContext == item);
                    if (item2Remove != null)
                    {
                        collection.Remove(item2Remove);
                    }
                }
            }
        }
示例#2
0
        internal bool RaiseTabItemClosingEvent(MetroTabItem closingItem)
        {
            var tabItemClosingEvent = this.TabItemClosingEvent;

            if (tabItemClosingEvent != null)
            {
                foreach (TabItemClosingEventHandler subHandler in tabItemClosingEvent.GetInvocationList().OfType <TabItemClosingEventHandler>())
                {
                    var args = new TabItemClosingEventArgs(closingItem);
                    subHandler.Invoke(this, args);
                    if (args.Cancel)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
0
 internal TabItemClosingEventArgs(MetroTabItem item)
 {
     ClosingTabItem = item;
 }