How to Stretch WPF Tab Item Headers to Parent Control Width

后端 未结 11 1948
花落未央
花落未央 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:44

    I am an old school style guy. and prefer this kind of functionality to encapsulate into the code of the control itself. My derived control looks like following:

        public class CustomTabControl :TabControl
    {
        protected override void OnRenderSizeChanged(System.Windows.SizeChangedInfo sizeInfo)
        {
            foreach (TabItem item in this.Items)
            {
                double newW = (this.ActualWidth / Items.Count) - 1;
                if (newW < 0) newW = 0;
    
                item.Width = newW;
            }            
        }       
    }
    

    and my XAML looks like

    
         
         
    
    

    Can someone explain why everyone prefers styling control instead of deriving.

提交回复
热议问题