private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AdjustColumnMinWidthToFitTabsBehavior behavior = (AdjustColumnMinWidthToFitTabsBehavior)d;

            // Unhook event handlers
            behavior.unHookFromTabEvents();

            // Hook to events on new tabs
            if (behavior.TabControl != null)
            {
                behavior.hookToTabEvents(behavior.TabControl.Items);
            }

            // Calculate and apply column width
            behavior.adjustColumnMinWidth();
        }
Esempio n. 2
0
        private void addColumnWidthBehavior(Grid g, int columnIndex, TabControl tabControl)
        {
            BehaviorCollection behaviors = Interaction.GetBehaviors(g);

            foreach (Behavior b in behaviors)
            {
                if (b is AdjustColumnMinWidthToFitTabsBehavior)
                {
                    return;
                }
            }

            AdjustColumnMinWidthToFitTabsBehavior widthBehavior = new AdjustColumnMinWidthToFitTabsBehavior()
            {
                Column     = columnIndex,
                TabControl = tabControl
            };

            behaviors.Add(widthBehavior);
        }
        private static void OnTabControlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AdjustColumnMinWidthToFitTabsBehavior behavior = (AdjustColumnMinWidthToFitTabsBehavior)d;

            // Unhook from events on previous tab control's tabs
            behavior.unHookFromTabEvents();
            behavior.clearItemsSourceBinding();

            if (e.NewValue is TabControl)
            {
                TabControl tabControl = (TabControl)e.NewValue;

                // Wire up events
                behavior.hookToTabEvents(tabControl.Items);
                behavior.setItemsSourceBinding(tabControl);

                // Calculate and apply column width
                behavior.adjustColumnMinWidth();
            }
        }