Ejemplo n.º 1
0
        internal void InitTabs()
        {
            Items.Clear();
            if (ItemsDataSource != null)
            {
                foreach (var item in ItemsDataSource)
                {
                    var newitem = new TabItem();

                    if (TabItemTemplate != null)
                    {
                        newitem.Content = TabItemTemplate.LoadContent();
                    }

                    if (TabHeaderItemTemplate != null)
                    {
                        newitem.Header = TabHeaderItemTemplate.LoadContent();
                    }

                    newitem.DataContext = item;
                    Items.Add(newitem);
                }
            }
        }
Ejemplo n.º 2
0
        void ItemsDataSource_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                if (e.NewStartingIndex > -1)
                {
                    foreach (var item in e.NewItems)
                    {
                        var newitem = new TabItem();

                        if (TabItemTemplate != null)
                        {
                            newitem.Content = TabItemTemplate.LoadContent();
                        }

                        if (TabHeaderItemTemplate != null)
                        {
                            newitem.Header = TabHeaderItemTemplate.LoadContent();
                        }

                        newitem.DataContext = item;

                        Items.Add(newitem);

                        this.SelectedItem = newitem;
                    }
                }
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                if (e.OldStartingIndex > -1)
                {
                    Items.RemoveAt(e.OldStartingIndex);
                }
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
            {
                Items.RemoveAt(e.OldStartingIndex);

                var newitem = new TabItem();

                if (TabItemTemplate != null)
                {
                    newitem.Content = TabItemTemplate.LoadContent();
                }

                if (TabHeaderItemTemplate != null)
                {
                    newitem.Header = TabHeaderItemTemplate.LoadContent();
                }

                newitem.DataContext = e.NewItems[0];

                Items.Add(newitem);

                Items.Insert(e.NewStartingIndex, newitem);
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                InitTabs();
            }
        }