How to Stretch WPF Tab Item Headers to Parent Control Width

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

    I was able to do this using a Converter like so:

    namespace WpfApplication1.Converters
    {
        public class SizeConverter : IValueConverter
        {
            #region IValueConverter Members
    
            public object Convert(object value, Type targetType, object parameter,
                System.Globalization.CultureInfo culture)
            {
                double width = Double.Parse(value.ToString());
                //Subtract 1, otherwise we could overflow to two rows.
                return .25 * width - 1;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter,
                System.Globalization.CultureInfo culture)
            {
                throw new NotSupportedException();
            }
    
            #endregion
        }
    }
    

    Then adding the namespace to my xaml:

    xmlns:local="clr-namespace:WpfApplication1.Converters"
    

    Then making all of the TabItems use the converter:

    
            
            
        
    

    x_Grid is the x:Name of the parent element I want the tabs to be 1/4 of, if that makes sense.

提交回复
热议问题