How to Stretch WPF Tab Item Headers to Parent Control Width

后端 未结 11 1953
花落未央
花落未央 2020-11-29 23:17

Is there a way in XAML to cause the tab item headers to stretch across the width of the tab control?

For example, I have three tabs: red, blue and green. If I have a

11条回答
  •  执念已碎
    2020-11-29 23:36

    I am using the following solution: In the main window i use a window re sized event and on tabcontrol Initialized event to set the Width of each Tab. The number '5' corresponds to my number of Tabs.

        private void tabchanger_Initialized(object sender, EventArgs e)
        {
            foreach (TabItem item in tabchanger.Items)
            {
                double newW = (tabchanger.ActualWidth / 5) - 1;
                if (newW < 0) newW = 0;
    
                item.Width = newW;
            }
    
        }
    
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            foreach (TabItem item in tabchanger.Items)
            {
                double newW = (tabchanger.ActualWidth / 5) - 1;
                if (newW < 0) newW = 0;
    
                item.Width = newW;
            }
        }
    

提交回复
热议问题