Exemplo n.º 1
0
        // Token: 0x060056D1 RID: 22225 RVA: 0x00180420 File Offset: 0x0017E620
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TabItem    tabItem          = d as TabItem;
            bool       flag             = (bool)e.NewValue;
            TabControl tabControlParent = tabItem.TabControlParent;

            if (tabControlParent != null)
            {
                tabControlParent.RaiseIsSelectedChangedAutomationEvent(tabItem, flag);
            }
            if (flag)
            {
                tabItem.OnSelected(new RoutedEventArgs(Selector.SelectedEvent, tabItem));
            }
            else
            {
                tabItem.OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, tabItem));
            }
            if (flag)
            {
                Binding binding = new Binding("Margin");
                binding.Source = tabItem;
                BindingOperations.SetBinding(tabItem, KeyboardNavigation.DirectionalNavigationMarginProperty, binding);
            }
            else
            {
                BindingOperations.ClearBinding(tabItem, KeyboardNavigation.DirectionalNavigationMarginProperty);
            }
            tabItem.UpdateVisualState();
        }
Exemplo n.º 2
0
        /// <summary>
        /// TabStripPlacement property changed handler.
        /// </summary>
        /// <param name="d">
        /// TabControl that changed its TabStripPlacement.
        /// </param>
        /// <param name="e">The DependencyPropertyChangedEventArgs.</param>
        private static void OnTabStripPlacementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TabControl tc = (TabControl)d;

            Debug.Assert(tc != null, "TabControl should not be null!");
            tc.UpdateTabPanelLayout((Dock)e.OldValue, (Dock)e.NewValue);

            foreach (object o in tc.Items)
            {
                TabItem tabItem = o as TabItem;
                if (tabItem != null)
                {
                    tabItem.UpdateVisualState();
                }
            }
        }
Exemplo n.º 3
0
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TabItem tabItem = d as TabItem;

            bool isSelected = (bool)e.NewValue;

            TabControl parentTabControl = tabItem.TabControlParent;

            if (parentTabControl != null)
            {
                parentTabControl.RaiseIsSelectedChangedAutomationEvent(tabItem, isSelected);
            }

            if (isSelected)
            {
                tabItem.OnSelected(new RoutedEventArgs(Selector.SelectedEvent, tabItem));
            }
            else
            {
                tabItem.OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, tabItem));
            }


            // KeyboardNavigation use bounding box reduced with DirectionalNavigationMargin when calculating the next element in directional navigation
            // Because TabItem use negative margins some TabItems overlap which would changes the directional navigation if we don't reduce the bounding box
            if (isSelected)
            {
                Binding binding = new Binding("Margin");
                binding.Source = tabItem;
                BindingOperations.SetBinding(tabItem, KeyboardNavigation.DirectionalNavigationMarginProperty, binding);
            }
            else
            {
                BindingOperations.ClearBinding(tabItem, KeyboardNavigation.DirectionalNavigationMarginProperty);
            }

            tabItem.UpdateVisualState();
        }
Exemplo n.º 4
0
        /// <summary>
        /// IsSelected changed handler
        /// </summary>
        /// <param name="d">TabItem that changed IsSelected.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TabItem tabItem = d as TabItem;

            Debug.Assert(tabItem != null);

            bool isSelected = (bool)e.NewValue;

            RoutedEventArgs args = new RoutedEventArgs();

            if (isSelected)
            {
                tabItem.OnSelected(args);
            }
            else
            {
                tabItem.OnUnselected(args);
            }

            // fire the IsSelectedChanged event for automation
            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected))
            {
                TabControl parentSelector = tabItem.TabControlParent;
                if (parentSelector != null)
                {
                    TabItemAutomationPeer tabItemPeer = GetTabItemAutomationPeer(tabItem);
                    if (tabItemPeer != null)
                    {
                        tabItemPeer.RaiseAutomationIsSelectedChanged(isSelected);
                    }
                }
            }

            tabItem.IsTabStop = isSelected;
            tabItem.UpdateVisualState();
        }
Exemplo n.º 5
0
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                int newSelectedIndex = -1;
                foreach (object o in e.NewItems)
                {
                    TabItem tabItem = o as TabItem;
                    if (tabItem == null)
                    {
                        throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, System.Windows.Controls.Properties.Resources.TabControl_InvalidChild, o.GetType().ToString()));
                    }
                    int index = Items.IndexOf(tabItem);
                    InsertIntoTabPanel(index, tabItem);

                    // If we are adding a selected item
                    if (tabItem.IsSelected)
                    {
                        newSelectedIndex = index;
                    }
                    else if (SelectedItem != GetItemAtIndex(SelectedIndex))
                    {
                        newSelectedIndex = Items.IndexOf(SelectedItem);
                    }
                    else if ((_desiredIndex < Items.Count) && (_desiredIndex >= 0))
                    {
                        // Coercion Workaround
                        newSelectedIndex = _desiredIndex;
                    }

                    tabItem.UpdateVisualState();
                }

                if (newSelectedIndex == -1)
                {
                    // If we are adding many items through xaml, one could
                    // already be specified as selected. If so, we don't
                    // want to override the value.
                    foreach (object item in Items)
                    {
                        TabItem tabItem = item as TabItem;
                        if (tabItem == null)
                        {
                            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, System.Windows.Controls.Properties.Resources.TabControl_InvalidChild, item.GetType().ToString()));
                        }

                        if (tabItem.IsSelected)
                        {
                            return;
                        }
                    }

                    // To follow WPF behavior, we only select the item if
                    // the user has not explicitly set the IsSelected field
                    // to false, or if there are 2 or more items in the
                    // TabControl.
                    if (Items.Count > 1 || ((Items[0] as TabItem).ReadLocalValue(TabItem.IsSelectedProperty) as bool?) != false)
                    {
                        newSelectedIndex = 0;
                    }
                }

                // When we add a new item into the selected position,
                // SelectedIndex does not change, so we need to update both
                // the SelectedItem and the SelectedIndex.
                SelectedItem  = GetItemAtIndex(newSelectedIndex);
                SelectedIndex = newSelectedIndex;
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (object o in e.OldItems)
                {
                    TabItem tabItem = o as TabItem;
                    RemoveFromTabPanel(tabItem);

                    // if there are no items, the selected index is set to
                    // -1
                    if (Items.Count == 0)
                    {
                        SelectedIndex = -1;
                    }
                    else if (Items.Count <= SelectedIndex)
                    {
                        SelectedIndex = Items.Count - 1;
                    }
                    else
                    {
                        SelectedItem = GetItemAtIndex(SelectedIndex);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                ClearTabPanel();
                SelectedIndex = -1;

                // For Setting the ItemsSource
                foreach (object item in Items)
                {
                    TabItem tabItem = item as TabItem;
                    if (tabItem == null)
                    {
                        throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, System.Windows.Controls.Properties.Resources.TabControl_InvalidChild, item.GetType().ToString()));
                    }
                    AddToTabPanel(tabItem);
                    if (tabItem.IsSelected)
                    {
                        SelectedItem = tabItem;
                    }
                }
                if (SelectedIndex == -1 && Items.Count > 0)
                {
                    SelectedIndex = 0;
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                break;
            }
        }