I have a simple dialog with a TextBlock that should resize with the window and show scrollbars when the content is wider than the TextBlock/Dialog. Without the ScrollViewer, it works fine - the TextBlock is as wide as the window. As soon as I add the ScrollViewer, the TextBlock gets much wider (it fits to the content width). Why is the ScrollViewer changing the TextBlock's behavior and how can I prevent this?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="A label"/>
<ScrollViewer Grid.Row="1" Grid.Column="0" Margin="10" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Border BorderThickness="0.5" BorderBrush="Gray">
<TextBlock MinHeight="200" MinWidth="600"
Text="Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... Some long text ... " />
</Border>
</ScrollViewer>
<Button Grid.Row="2" Grid.Column="0" Width="80" Margin="0 10 15 15" Height="25" HorizontalAlignment="Right" Content="OK"/>
</Grid>
Because ScrollViewer provides your controls as many space as they need and helps to scroll them. I think your problems is border, you just need to place ScrollViewer inside border, and everything will look good.