I am trying to implement a kind of single-line tab control in WPF which shows scroll buttons left and right of the area containing the tabs. The tabs are implemented inside a custom control. The scroll buttons shall be displayed only if the window is too small to display all tabs.
When the window is resized by dragging on its borders, everything works as expected.
But when the window is maximimized and then restored, then the right scroll button remains hidden.

The problem seems to appear only if the `Visibility` property of the right scroll button is data-bound to a dependency property of the custom control that is updated within the custom control's Measure pass.

My question is: am I using WPF correctly here, or is there something that needs to be done in a different way? (Please note: I need to use the data-binding and the custom control; therefore please avoid answers that suggest to take a completely different approach.)

Here is a small sample program which illustrates the problem:

When width is small:

![Small window](https://i.stack.imgur.com/zlb4H.png)

When width is large:

![Large window](https://i.stack.imgur.com/qYzFs.png)

These are the files of the sample program:

MainWindow.xaml:

```
<Window x:Class="GridTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gridTest="clr-namespace:GridTest"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="theGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions> 
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Button x:Name="btnScrollLeft" Content="&lt;" Grid.Row="0" Grid.Column="0" Width="30"/>
        <gridTest:MyCustomControl x:Name="cust" Grid.Row="0" Grid.Column="1"/>
        <Button x:Name="btnScrollRight" Content="&gt;" Grid.Row="0" Grid.Column="2" Width="30"
                Visibility="{Binding ElementName=cust, Path=ShowButton}"/>
        <TextBox Text="The content goes here..." Grid.Row="1" Grid.ColumnSpan="3"
                 Background="LightGreen" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
        <Button x:Name="btnRedraw" Grid.Row="1" Grid.Column="1" Content="Redraw" VerticalAlignment="Bottom"
                HorizontalAlignment="Center" Click="btnRedraw_Click" />
    </Grid>
</Window>

```

MainWindow.xaml.cs:

```
using System.Windows;
namespace GridTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnRedraw_Click(object sender, RoutedEventArgs e)
        {
            theGrid.InvalidateMeasure();
        }
    }
}

```

MyCustomControl.cs:

```
using System;
using System.Windows;
using System.Windows.Controls;

namespace GridTest
{
    public class MyCustomControl : Control
    {
        static MyCustomControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomControl), new FrameworkPropertyMetadata(typeof(MyCustomControl)));
        }

        public Visibility ShowButton
        {
            get { return (Visibility)GetValue(ShowButtonProperty); }
            set { SetValue(ShowButtonProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ShowButton.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ShowButtonProperty =
            DependencyProperty.Register("ShowButton", typeof(Visibility), typeof(MyCustomControl), new UIPropertyMetadata(Visibility.Visible));

        protected override Size MeasureOverride(Size constraint)
        {
            if (constraint.Width > 800)
            {
                ShowButton = Visibility.Collapsed;
            }
            else
            {
                ShowButton = Visibility.Visible;
            }

            double width = Math.Min(2000.0, constraint.Width);
            double height = Math.Min(50.0, constraint.Height);

            return new Size(width, height);
        }
    }
}

```

Generic.xaml:

```
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:GridTest">

    <Style TargetType="{x:Type local:MyCustomControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MyCustomControl}">
                    <Border Background="LightCyan">
                        <TextBlock VerticalAlignment="Center" TextAlignment="Center">Custom Control</TextBlock>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

```

The problem can be reproduced as follows:

* Make sure that the window is small, such that the right scroll button is visible.
* Now maximize the window. => The right scroll button should become invisible.
* Now restore the window to its original size. => The right scroll button should become visible again. (The problem is: the right scroll button remains invisible.)

**EDIT**: Just for information: I could reproduce the problem with both VS2010+.NET4.0 and VS2013+.NET4.51.