MinLines and MaxLines on TextBox not working

Yes, i have too faced this problem. The TextBox will not initially be sized properly at startup and you can workaround this by binding the Text property with an startup text(Say a balnk space value " ").

XAML:

<StackPanel Margin="5,0,5,0" VerticalAlignment="Center">
 <DockPanel Margin="5" >
 <Label Content="Prompt"/>
 <TextBox MaxLines="3"
         MinLines="3" x:Name="text"
         VerticalScrollBarVisibility="Auto"
         Text="{Binding StartUpText}"
         AcceptsReturn="True"
         TextWrapping="Wrap" TextChanged="text_TextChanged" Loaded="text_Loaded"  />
 </DockPanel>
</StackPanel>

C#:

public MainWindow()
    {
        InitializeComponent();
        this.DataContext=this;
         StartUpText = " ";
    }

private string startUpText;
public string StartUpText
{
  get { return startUpText; }
  set
  {
    if (value != startUpText)
    {
        startUpText = value;
    }
  }
}

Tags:

Wpf

Xaml

Textbox